Several methods of deleting directories in php. This article provides three methods of deleting directories in php. If you are looking for the php code to delete a directory or delete all files in the directory, come and take a look.
php tutorial several ways to delete a directory
This article provides three methods on php to delete a directory. If you are looking for the php code to delete a directory or delete all files under a directory, come and take a look.
deletedir($dir)
{
if (rmdir($dir)==false && is_dir($dir)) {
If ($dp = opendir($dir)) {
While (($file=readdir($dp)) != false) {
If (is_dir($file) && $file!='.' && $file!='..') {
deletedir($file);
} else {
unlink($file);
}
}
closedir($dp);
} else {
exit('www.aimeige.com.cn not permission');
}
}
}
To delete a directory, use rmdir to delete it
//For example, a folder downstream of www.bkjia.com/ where the current file is located
@$flag = rmdir("www.bkjia.com/");
if($flag)
{echo "www.zhutiai.com deleted successfully";}
else
{echo "www.bkjia.com deletion failed";}
Let’s look at a php method to delete a folder and all files under it
function deldir($dir) {
$dh=opendir($dir);
while ($file=readdir($dh)) {
If($file!=”.” && $file!=”..”) {
$fullpath=$dir.”/”.$file;
If(!is_dir($fullpath)) {
unlink($fullpath);//mb.php100.com
} else {
deldir($fullpath);
}
}
}closedir($dh);
if(rmdir($dir)) {
Return true;
} else {
Return false;
}
}