Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]usuwanie całej zawartości katalogów
-rea-
post 11.06.2012, 19:41:41
Post #1





Goście







Jak zrobić, aby w php usunąć zawartość wskazanego katalogu? Mam taki kod:

  1. function removeDir($path)
  2. {
  3. $dir = new DirectoryIterator($path);
  4. foreach ($dir as $fileinfo)
  5. {
  6. if ($fileinfo->isFile() || $fileinfo->isLink())
  7. {
  8. unlink($fileinfo->getPathName());
  9. }
  10. elseif (!$fileinfo->isDot() && $fileinfo->isDir() &&$fileinfo->getPathName($path))
  11. {
  12. removeDir($fileinfo->getPathName());
  13. }
  14. }
  15. rmdir($path);
  16. }


Jednak on usuwa też katalog który został podany, jak temu zapobiec, aby była skasowana tylko jego cała zawartość (pliki i katalogi).
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Rysh
post 11.06.2012, 20:41:03
Post #2





Grupa: Zarejestrowani
Postów: 821
Pomógł: 111
Dołączył: 11.09.2006
Skąd: Biała Podlaska

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


Spróbuj coś takiego:
  1. function removeDir($path, $del = false)
  2. {
  3. $dir = new DirectoryIterator($path);
  4. foreach ($dir as $fileinfo)
  5. {
  6. if ($fileinfo->isFile() || $fileinfo->isLink())
  7. {
  8. unlink($fileinfo->getPathName());
  9. }
  10. elseif (!$fileinfo->isDot() && $fileinfo->isDir() &&$fileinfo->getPathName($path))
  11. {
  12. removeDir($fileinfo->getPathName(), TRUE);
  13. }
  14. }
  15. if($del) {
  16. rmdir($path);
  17. }
  18. }


--------------------
Go to the top of the page
+Quote Post

Posty w temacie


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: 14.08.2025 - 14:29