Home > Backend Development > PHP Tutorial > PHP batch recursive deletion of folders and files

PHP batch recursive deletion of folders and files

WBOY
Release: 2016-07-25 08:43:06
Original
747 people have browsed it
The rmdir that comes with PHP can only delete empty directories. This rrmdir can recursively delete the directory and all the files in the directory
  1. function rrmdir($dir) {
  2. if (is_dir($dir)) {
  3. $objects = scandir($dir);
  4. foreach ($objects as $object) {
  5. if ($object != “.” && $object != “..”) {
  6. if (filetype($dir.”/”.$ object) == “dir”) rrmdir($dir.”/”.$object); else unlink($dir.”/”.$object);
  7. }
  8. }
  9. reset($objects);
  10. }
  11. }
Copy code

php


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template