8

原生php递归删除文件+文件夹

 2 years ago
source link: https://blog.p2hp.com/archives/8748
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

原生php递归删除文件+文件夹 | Lenix Blog

原生php递归删除文件+文件夹

<?php
function deldir($dirname){
if(file_exists($dirname)) {//判断是否存在文件夹
$dir=opendir($dirname);//打开文件夹
while($filename=readdir($dir)){//读取123文件夹里面的数据
if($filename!="." && $filename!=".."){//除去.并且..除外
$file=$dirname."/".$filename;
if(is_dir($file)){
deldir($file); //使用递归删除子目录,就是说判断123文件夹里面有没有文件夹,如果有遍历然后删除
}else{
echo '删除文件<b>'.$file.'</b>成功<br>';
unlink($file);
closedir($dir);
echo '删除目录<b>'.$dirname.'</b>成功<br>';
rmdir($dirname);
deldir('D:\123');//比如文件在d盘的123目录下
?>

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK