Home > Backend Development > PHP Tutorial > Several ways to delete a directory in php_PHP tutorial

Several ways to delete a directory in php_PHP tutorial

WBOY
Release: 2016-07-20 11:01:58
Original
985 people have browsed it

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;
}
}


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445402.htmlTechArticle Several ways to delete directories in php. This article provides three ways to delete directories in php. If you are looking for deletion Directory or delete the php code of all files in the directory and come in and take a look. php tutorial...
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