Home >Backend Development >PHP Tutorial >PHP defines a recursive function to delete the entire directory

PHP defines a recursive function to delete the entire directory

WBOY
WBOYOriginal
2016-07-25 08:43:35929browse
  1. if ($dh = @opendir($dir)) {
  2. while (($file = readdir ($dh)) != false) {
  3. if (($file == ".") || ($file == "..")) continue;
  4. if (is_dir($dir . '/' . $file))
  5. delete_directory($dir . '/' . $file);
  6. else
  7. unlink($dir . '/' . $file);
  8. }
  9. @closedir($dh);
  10. rmdir($dir);
  11. }
  12. }
  13. $dir = "./fakeDir";
  14. delete_directory($dir);
  15. ?>
复制代码

php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn