Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] katalogi i pliki
albercik1983
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 28.02.2009

Ostrzeżenie: (0%)
-----


Witam.
Mam problem z utworzeniem katalogu w istniejacym już katalogu "user".

Jeśli dam:

mkdir($_POST['login']);
fopen (user.php, a);

tworzy katalog o nazwie zmiennej i plik userphp (bez kropki ;/) w katalogu głównym.
Teraz jeśli chcę aby folder o nazwie zmiennej został stworzony w istniejącym katalogu "user" to daję:

mkdir(user/$_POST['login']);
fopen (user/$_POST['login']/user.txt, a);

to wyskakuje błąd:
Warning: mkdir() [function.mkdir]: File exists
Warning: Division by zero

jeśli dam:
mkdir(../user/$_POST['login']);
fopen (../user/$_POST['login']/user.txt, a);
to mam błąd:
Parse error: parse error, unexpected '.', expecting ')'

Ktoś wie jak to rozwiązać?
Go to the top of the page
+Quote Post
kefirek
post
Post #2





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

Ostrzeżenie: (0%)
-----


Zobacz tak
  1. <?php
  2. fopen ('../user/'.$_POST['login'].'/user.txt', 'a');
  3. mkdir('../user/'.$_POST['login']);
  4. ?>


Ten post edytował kefirek 28.02.2009, 21:35:25
Go to the top of the page
+Quote Post
batman
post
Post #3





Grupa: Moderatorzy
Postów: 2 921
Pomógł: 269
Dołączył: 11.08.2005
Skąd: 127.0.0.1




Cytat
Warning: mkdir() [function.mkdir]: File exists
Ten błąd oznacza, że próbujesz utworzyć katalog, który już istnieje. Zanim zaczniesz tworzyć katalog, sprawdź funkcją file_exists czy istnieje.


--------------------
I would love to change the world, but they won't give me the source code.
My software never has bugs. It just develops random features.
Go to the top of the page
+Quote Post
albercik1983
post
Post #4





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 28.02.2009

Ostrzeżenie: (0%)
-----


Cytat(kefirek @ 28.02.2009, 21:34:47 ) *
Zobacz tak
  1. <?php
  2. fopen ('../user/'.$_POST['login'].'/user.txt', 'a');
  3. mkdir('../user/'.$_POST['login']);
  4. ?>


zrobiłem tak i mam błąd Parse error: parse error, unexpected '<'

właśnie o to chodzi że folder nie istnieje.
istnieje tylko folder "user" w którym ma zostać stworzony nowy katalog..
Go to the top of the page
+Quote Post
kefirek
post
Post #5





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

Ostrzeżenie: (0%)
-----


A tak
  1. <?php
  2. fopen("/user/".$_POST['login']."/user.txt", "a");
  3. mkdir("/user/".$_POST['login']);
  4. ?>
Go to the top of the page
+Quote Post
albercik1983
post
Post #6





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 28.02.2009

Ostrzeżenie: (0%)
-----


jeśli dam:

mkdir("/user/".$_POST['login']);
fopen("/user/".$_POST['login']."/user.txt", "a");

to mam błąd:
Warning
: mkdir() [function.mkdir]: No such file or directory

może są jakieś polecenia żeby najpierw otworzyć "user", potem dodać do niego $_POST['login'], otwprzyć go i utworzyć plik...
Go to the top of the page
+Quote Post
kefirek
post
Post #7





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

Ostrzeżenie: (0%)
-----


To dziwne robie tak i działa poprawnie
  1. <?php
  2. $test = 'test';
  3. mkdir("user/".$test);
  4. fopen("user/".$test."/user.txt", "a");
  5. ?>
Go to the top of the page
+Quote Post
patryk20120
post
Post #8





Grupa: Zarejestrowani
Postów: 256
Pomógł: 1
Dołączył: 20.04.2008

Ostrzeżenie: (0%)
-----


To powinno działać tongue.gif
  1. <?php
  2. mkdir ("user/".$_POST['login'], 0700);
  3. fopen('user/'.$_POST['login'].'/text.txt', 'a');
  4. ?>
Go to the top of the page
+Quote Post
albercik1983
post
Post #9





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 28.02.2009

Ostrzeżenie: (0%)
-----


$test = 'test';
mkdir("user/".$test);
fopen("user/".$test."/user.txt", "a");


działa już

podziękowania dla kefirka smile.gif

jednak się rozmyśliłem i nie chcę, aby folder tworzył się o nazwie takiej jak login, tylko takiej jak nr id w bazie danych.

$dana=mysql_query("select user_id from user where user_login='".htmlspecialchars($_POST["login"]."'")
$pliki=mysql_result($dana)
mkdir("user/".$pliki);
fopen("user/".$pliki."/user.php", "r");

i nie działa ;/

Ten post edytował albercik1983 28.02.2009, 22:02:03
Go to the top of the page
+Quote Post
kefirek
post
Post #10





Grupa: Zarejestrowani
Postów: 781
Pomógł: 256
Dołączył: 29.06.2008

Ostrzeżenie: (0%)
-----


Zobacz może tak
  1. <?php
  2. $dana = mysql_result(mysql_query("SELECT user_id FROM user WHERE user_login='".mysql_real_escape_string($_POST["login"]."'"),0);
  3. mkdir("user/".$dana);
  4. fopen("user/".$dana."/user.php", "r");
  5. ?>
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 16:14