Home  >  Article  >  Backend Development  >  PHP delete a folder and all files under the folder, _PHP tutorial

PHP delete a folder and all files under the folder, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:55:02973browse

PHP deletes the folder and all files under it,


function deldir($dir) {
//Delete the files in the directory first:
$dh=opendir($dir);
while ($file=readdir ($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir. "/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
                                                                                                    >
closedir($dh);
//Delete the current folder:
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
?>

http://www.bkjia.com/PHPjc/993269.htmlwww.bkjia.com
true

http: //www.bkjia.com/PHPjc/993269.html

TechArticle

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