Home > Backend Development > PHP Tutorial > 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
Release: 2016-07-13 09:55:02
Original
994 people have browsed it

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

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