Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Kasowanie CAŁYCH katalogów.
moto0095
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Witam. Szukam w Google i nic jakoś nie znalazłem.
A mianowicie mam sobie folder z plikami i podfolderami.
I chciałbym do usunąć ale cały łącznie z tymi plikami i podfolderami.
Bo ulink() raczej tego nie zrobię.
Wie ktoś jak to zrobić (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 16)
phpion
post
Post #2





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Zobacz przykład użytkownika Eddy Vlad w dokumentacji dla unlink. Powinno cię zadowolić.
Go to the top of the page
+Quote Post
moto0095
post
Post #3





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Jakiś link czy coś byś podał (IMG:style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
tehaha
post
Post #4





Grupa: Zarejestrowani
Postów: 1 748
Pomógł: 388
Dołączył: 21.08.2009
Skąd: Gdynia

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


kiedyś znalazłem tą funkcję w internecie, działa skutecznie
  1. function recursive_remove_directory($directory, $empty=FALSE)
  2. {
  3. // if the path has a slash at the end we remove it here
  4. if(substr($directory,-1) == '/')
  5. {
  6. $directory = substr($directory,0,-1);
  7. }
  8.  
  9. // if the path is not valid or is not a directory ...
  10. if(!file_exists($directory) || !is_dir($directory))
  11. {
  12. // ... we return false and exit the function
  13. return FALSE;
  14.  
  15. // ... if the path is not readable
  16. }elseif(!is_readable($directory))
  17. {
  18. // ... we return false and exit the function
  19. return FALSE;
  20.  
  21. // ... else if the path is readable
  22. }else{
  23.  
  24. // we open the directory
  25. $handle = opendir($directory);
  26.  
  27. // and scan through the items inside
  28. while (FALSE !== ($item = readdir($handle)))
  29. {
  30. // if the filepointer is not the current directory
  31. // or the parent directory
  32. if($item != '.' && $item != '..')
  33. {
  34. // we build the new path to delete
  35. $path = $directory.'/'.$item;
  36.  
  37. // if the new path is a directory
  38. if(is_dir($path))
  39. {
  40. // we call this function with the new path
  41. recursive_remove_directory($path);
  42.  
  43. // if the new path is a file
  44. }else{
  45. // we remove the file
  46. unlink($path);
  47. }
  48. }
  49. }
  50. // close the directory
  51. closedir($handle);
  52.  
  53. // if the option to empty is not set to true
  54. if($empty == FALSE)
  55. {
  56. // try to delete the now empty directory
  57. if(!rmdir($directory))
  58. {
  59. // return false if not possible
  60. return FALSE;
  61. }
  62. }
  63. // return success
  64. return TRUE;
  65. }
  66. }
Go to the top of the page
+Quote Post
nospor
post
Post #5





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




jejku... wchodzisz do manuala php i odnajdujesz w nim funkcję unlink() - o tym wlasnie mowil phpion
Go to the top of the page
+Quote Post
moto0095
post
Post #6





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Super tehaha, ale gdzie tam podać nazwę folderu który ma zostać usunięty (IMG:style_emoticons/default/winksmiley.jpg) (IMG:style_emoticons/default/questionmark.gif)
Go to the top of the page
+Quote Post
tehaha
post
Post #7





Grupa: Zarejestrowani
Postów: 1 748
Pomógł: 388
Dołączył: 21.08.2009
Skąd: Gdynia

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


no chyba widać że jedną ze zmiennych przekazywanych do funkcji jest zmienna $directory , czyli ścieżka do katalogu jaki ma być usunięty
Go to the top of the page
+Quote Post
nospor
post
Post #8





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




  1. recursive_remove_directory('mysl/chlopie/bo/temat/ci/zamkna');
Go to the top of the page
+Quote Post
moto0095
post
Post #9





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Sorki nie przyjrzałem się dokładnie.
A i nospor wiem że to tak powinno być (IMG:style_emoticons/default/winksmiley.jpg)
Dzięki wielkie. Temat do zamknięcia (IMG:style_emoticons/default/winksmiley.jpg)

Stworzyłem przykładowy katalog i zawartość usunęło ale katalogu nie i pokazało się

Warning: rmdir(katalog) [function.rmdir]: Permission denied in /home/****/usun.php on line 58

Dlaczego nie usunęło katalogu (IMG:style_emoticons/default/questionmark.gif)

u mnie linia 58 to:
if(!rmdir($directory))

Ten post edytował moto0095 27.04.2010, 13:05:12
Go to the top of the page
+Quote Post
nospor
post
Post #10





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




Odpowiedź na pytanie "Dlaczego" masz w komunikacie bledu. Przeczytales go?

Cytat
A i nospor wiem że to tak powinno być
Jakbys wiedzial to bys sie nie pytal. a zapytales.
Go to the top of the page
+Quote Post
moto0095
post
Post #11





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Błąd przeczytałem.
Ale nie wiem co jest nie tak w kodzie (IMG:style_emoticons/default/winksmiley.jpg)
Proszę o pomoc.
Go to the top of the page
+Quote Post
nospor
post
Post #12





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




chodzilo mi o przeczytanie ze zrozumieniem

blad mowi ze nie masz praw. Kod jest ok ino katalog ma takie prawa ze skrypt php nie ma prawa go usunac.
Go to the top of the page
+Quote Post
moto0095
post
Post #13





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Cytat(nospor @ 27.04.2010, 14:08:50 ) *
Jakbys wiedzial to bys sie nie pytal. a zapytales.

Wiem walnąłem kompletną głupotę (IMG:style_emoticons/default/winksmiley.jpg)


Katalog ma chmod ustawione na 0777
Go to the top of the page
+Quote Post
nospor
post
Post #14





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




Cytat
Katalog ma chmod ustawione na 0777
A jak to sprawdziles? Nie zebym ci nie wierzyl, ale wolalbym miec pewnosc (IMG:style_emoticons/default/winksmiley.jpg)
Go to the top of the page
+Quote Post
moto0095
post
Post #15





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Bo sam mu takie ustawiałem (IMG:style_emoticons/default/winksmiley.jpg)
A po za tym w FILEZILLA jest taka informacja obok pliku - jest kolumna PRAWA DOSTĘPU (IMG:style_emoticons/default/winksmiley.jpg)

Więc miej pewność że ten katalog ma chmod 0777

Zmieniałem chmody na 0755 i 766 ale to nic nie daje (IMG:style_emoticons/default/sad.gif)

Ten post edytował moto0095 27.04.2010, 13:24:44
Go to the top of the page
+Quote Post
phpion
post
Post #16





Grupa: Moderatorzy
Postów: 6 072
Pomógł: 861
Dołączył: 10.12.2003
Skąd: Dąbrowa Górnicza




Cytat(moto0095 @ 27.04.2010, 14:33:33 ) *
Zmieniałem chmody na 0755 i 766 ale to nic nie daje (IMG:style_emoticons/default/sad.gif)

No odbieranie uprawnień w tym momencie raczej nie pomoże.
Go to the top of the page
+Quote Post
moto0095
post
Post #17





Grupa: Zarejestrowani
Postów: 247
Pomógł: 9
Dołączył: 12.03.2010

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


Cytat
No odbieranie uprawnień w tym momencie raczej nie pomoże.


Wiem. A co pomoże (IMG:style_emoticons/default/questionmark.gif)

A jak zrobić, aby usuwała się sama treść folderu i jego podkatalogi (IMG:style_emoticons/default/questionmark.gif)

Okey poradziłem już sobie
Temat do zamknięcia (IMG:style_emoticons/default/winksmiley.jpg) (IMG:style_emoticons/default/offtopic.gif)
Go to the top of the page
+Quote Post

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

 



RSS Aktualny czas: 29.09.2025 - 09:35