php delete folder and all files under it_PHP tutorial

WBOY
Release: 2016-07-13 17:13:21
Original
944 people have browsed it

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