The original method of PHP deleting directories and files is to first check whether there are files in this directory. If so, if it is a folder, then call this function to delete it. If it is a file, directly call unlink to delete it, and finally delete the directory.
When deleting a folder, you must first ensure that you have this permission!
The code is as follows
|
Copy code | ||||
removefunctionDir($dirName)
{
If(! is_dir($dirName))
{
return false;
}
$handle = @opendir($dirName);
While(($file = @readdir($handle)) !== false)
{
If($file != '.' && $file != '..')
$dir = $dirName . '/' . $file;
is_dir($dir) ? removeDir($dir) : @unlink($dir);
}
closedir($handle);
Return rmdir($dirName);
}
?>