Home >Backend Development >PHP Tutorial >php delete folder and all files under it_PHP tutorial

php delete folder and all files under it_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:13:21968browse

We use unlink deletion to delete files and directories in php. If we want to delete a directory that is not empty, we mainly use readdir and opendir to traverse the directory.

The code is as follows
 代码如下 复制代码

// 删除文件夹,及其其下所有文件

function deldir($dir) {

$dh=opendir($dir);

while ($file=readdir($dh)) {

if($file!="." && $file!="..") {

$fullpath=$dir."/".$file;

if(!is_dir($fullpath)) {

unlink($fullpath);

} else {

deldir($fullpath);

}

}

}

closedir($dh);

if(rmdir($dir)) {

return true;

} else {

return false;

}

}
?>

Copy code
// Delete the folder and all files under it

function deldir($dir) {

}
?> http://www.bkjia.com/PHPjc/629190.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/629190.htmlTechArticleWe use unlink deletion to delete files and directories in php. If we want to delete a directory that is not empty, we mainly use it. readdir and opendir are used to traverse the directory. The code is as follows Copy the code...
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