How to retrieve files deleted from the Recycle Bin using PHP, delete files and folders

PHP中文网
Release: 2023-02-28 21:30:02
Original
2791 people have browsed it

How to retrieve files deleted from the recycle bin using PHP to delete files and folders. Use the two functions unlink and rmdir

Let’s take a look at the code first

The code is as follows:

<? 
function deldir($dir) { 
//先删除目录下的文件: 
$dh=opendir($dir); 
while ($file=readdir($dh)) { 
if($file!="." && $file!="..") { 
$fullpath=$dir."/".$file; 
if(!is_dir($fullpath)) { 
unlink($fullpath); 
} else { 
deldir($fullpath); 
} 
} 
} 
closedir($dh); 
//删除当前文件夹: 
if(rmdir($dir)) { 
return true; 
} 
else { 
return false; 
} 
} 
?>
Copy after login

unlink() function is used to delete files . Returns true if successful, false if failed. The rmdir() function is used to delete empty directories. It attempts to delete the directory specified by dir. The directory must be empty and must have appropriate permissions.
An example: Delete all ".svn" folders under a certain folder (including their contents also need to be deleted).

The code is as follows:

<?php 
function delsvn($dir) { 
$dh=opendir($dir); 
//找出所有".svn" 的文件夹: 
while ($file=readdir($dh)) { 
if($file!="." && $file!="..") { 
$fullpath=$dir."/".$file; 
if(is_dir($fullpath)) { 
if($file==".svn"){ 
delsvndir($fullpath); 
}else{ 
delsvn($fullpath); 
} 
} 
} 
} 
closedir($dh); 
} 
function delsvndir($svndir){ 
//先删除目录下的文件: 
$dh=opendir($svndir); 
while($file=readdir($dh)){ 
if($file!="."&&$file!=".."){ 
$fullpath=$svndir."/".$file; 
if(is_dir($fullpath)){ 
delsvndir($fullpath); 
}else{ 
unlink($fullpath); 
} 
} 
} 
closedir($dh); 
//删除目录文件夹 
if(rmdir($svndir)){ 
return true; 
}else{ 
return false; 
} 
} 
$dir=dirname(__FILE__); 
//echo $dir; 
delsvn($dir); 
?>
Copy after login

The above introduces how to retrieve files deleted from the Recycle Bin in PHP. Delete files and folders using the two functions unlink and rmdir, including how to retrieve files deleted from the Recycle Bin. Content, please pay attention to the PHP Chinese website (www.php.cn) for more related content!

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