How to recursively delete directories and files in php, _PHP tutorial

WBOY
Release: 2016-07-13 10:08:29
Original
714 people have browsed it

How to recursively delete directories and files in php,

The example in this article describes the method of recursively deleting directories and files in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

<&#63;php
function deldir($path){
 $dh = opendir($path);
 var_dump(readdir($dh));
 while(($d = readdir($dh)) !== false){
 if($d == '.' || $d == '..'){//如果为.或..
 continue;
 }
 $tmp = $path.'/'.$d;
 if(!is_dir($tmp)){//如果为文件
 unlink($tmp);
 }else{//如果为目录
 deldir($tmp);
 }
 }
 closedir($dh);
 rmdir($path); 
}
$path = "./e";
deldir($path);
&#63;>
Copy after login

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/950892.htmlTechArticleHow to recursively delete directories and files in php. This article describes the method of recursively deleting directories and files in php. Share it with everyone for your reference. The specific implementation method is as follows: phpfunction d...
Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!