Home >Backend Development >PHP Tutorial >How to retrieve files deleted from the recycle bin. PHP custom function to recursively delete files and directories.

How to retrieve files deleted from the recycle bin. PHP custom function to recursively delete files and directories.

WBOY
WBOYOriginal
2016-07-29 08:43:311169browse

Copy the code The code is as follows:


/*—————————————————————— */
//– Recursively delete files and directories
//– Example: del_dir ('../cache/'); Note: The returned / is required
//– $type forces deletion of the directory, true is yes, false is no
/*—————————————— —————— */
function del_dir ($dir,$type=true)
{
$n=0;
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
//.svn ignore svn version control information
if ( $file == '.' or $file =='..' or $ file == '.svn')
{
continue;
}
if (is_file ($dir.$file))
{
unlink($dir.$file);
$n++;
}
if (is_dir ( $dir.$file))
{
del_dir ($dir.$file.'/');
if ($type)
{
$n++;
rmdir($dir.$file.'/');
}
}
}
}
closedir($dh);
}
return $n;
}

The above introduces how to retrieve files deleted from the Recycle Bin. The PHP custom function recursively deletes files and directories, including how to retrieve files deleted from the Recycle Bin. I hope it will be helpful to friends who are interested in PHP tutorials.

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