Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]usuwanie całej zawartości katalogów
-rea-
post
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
Michael2318
post
Post #2





Grupa: Zarejestrowani
Postów: 651
Pomógł: 116
Dołączył: 3.06.2012
Skąd: Lędziny

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


Ja używam tego:

  1. function destroy($dir) {
  2. $mydir = opendir($dir);
  3. while(false !== ($file = readdir($mydir))) {
  4. if($file != "." && $file != "..") {
  5. chmod($dir.$file, 0777);
  6. if(is_dir($dir.$file)) {
  7. chdir('.');
  8. destroy($dir.$file.'/');
  9. rmdir($dir.$file) or DIE("couldn't delete $dir$file<br />");
  10. }
  11. else
  12. unlink($dir.$file) or DIE("couldn't delete $dir$file<br />");
  13. }
  14. }
  15. closedir($mydir);
  16. }
Go to the top of the page
+Quote Post

Posty w temacie


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: 25.12.2025 - 20:32