Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php] tworzenie katalogow
mefjiu
post 25.07.2007, 09:56:47
Post #1





Grupa: Zarejestrowani
Postów: 313
Pomógł: 5
Dołączył: 22.03.2005

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


Witam chciałbym napisać skrypcik który będzie tworzył katalogi pobierając dane z pliku dane.txt

plik ten wygląda następująco.

sdfsdfsd
sdf43sdf
dfsfertsd3
44eerf
dfs45rt5gw
rf54tef

Dane oddzielone enterami

Natopmiast skrypt php wygląda tak
  1. <?
  2. @ $wp = fopen("dane.txt",'r');
  3. if (!wp)
  4. {
  5. echo "blad otwarcia pliku";
  6. }
  7. while(!feof($wp))
  8. {
  9. $dane = fgets($wp, 999);
  10. mkdir($dane, 0777);
  11. }
  12. fclose($wp);
  13.  
  14. ?>



Problem polega na tym że tworzy tylko pierwszy katalog z listy natomiast potem sypie błędami

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 11

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 11

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 11

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 11

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 11
Go to the top of the page
+Quote Post
Cienki1980
post 25.07.2007, 10:01:44
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 590
Pomógł: 40
Dołączył: 11.01.2007
Skąd: Centrum

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


Zamiast używać fopen skorzystaj z file" title="Zobacz w manualu PHP" target="_manual a w wyniku dostaniesz tablicę, gdzie każdy element tablicy będzie zawierał kolejną linijkę z pliku.
Wtedy będzie Ci łatwiej to stworzyć ...

Acha pamiętaj o trim() na każdym wierszu ( elemencie tablicy )


--------------------
404
Go to the top of the page
+Quote Post
mefjiu
post 25.07.2007, 10:10:49
Post #3





Grupa: Zarejestrowani
Postów: 313
Pomógł: 5
Dołączył: 22.03.2005

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


przerobiłem to tak jak mówiłeś i dalej to samo

  1. <?
  2. $lines = file('dane.txt');
  3. foreach ($lines as $line_num => $line) {
  4. $trimmed = trim($line, " n.");
  5. mkdir($trimmed, 0777);
  6. }
  7. ?>



błędy
Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 5

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 5

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 5

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 5

Warning: mkdir() [function.mkdir]: Invalid argument in C:\Program Files\WebServ\httpd\test.php on line 5

Warning: mkdir() [function.mkdir]: File exists in C:\Program Files\WebServ\httpd\test.php on line 5
Go to the top of the page
+Quote Post
nospor
post 25.07.2007, 10:18:09
Post #4





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




nie: $trimmed = trim($line, " \n.");
a: $trimmed = trim($line);
Widze ze masz winde a ta ma inne znaki konca wiersza niz \n. Dlatego lepiej usuwac wszystkie biale znaki


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
mefjiu
post 25.07.2007, 10:27:35
Post #5





Grupa: Zarejestrowani
Postów: 313
Pomógł: 5
Dołączył: 22.03.2005

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


działa dziękuję pięknie :-)
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 Wersja Lo-Fi Aktualny czas: 12.06.2025 - 12:28