Home  >  Article  >  Backend Development  >  How to recursively delete directories and files in php, _PHP tutorial

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

WBOY
WBOYOriginal
2016-07-13 10:08:29712browse

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;>

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...
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