龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

删除文件以及对应的文件夹

时间:2014-07-22 14:52来源: 作者: 点击:
分享到:
删除目录及所包含文件函数
删除目录及所包含文件函数 
<?php 
//注意 $dir文件名   eg:admin/runtime 
//删除目录及所包含文件函数 
function deldir($dir) { 
     //打开文件目录 
     $dh = opendir($dir); 
     //循环读取文件 
     while ($file = readdir($dh)) { 
         if($file != '.' && $file != '..') { 
             $fullpath = $dir . '/' . $file; 
         
    //判断是否为目录 
             if(!is_dir($fullpath)) { 
        echo $fullpath."已被删除<br>"; 
                  //如果不是,删除该文件 
                 if(!unlink($fullpath)) {               
                 } 
             } else { 
                 //如果是目录,递归本身删除下级目录             
      deldir($fullpath); 
             } 
         } 
    } 
     //关闭目录 
     closedir($dh); 
    //删除目录 

   //if(rmdir($dir)) { 
     //    return true; 
//    } else { 
     //    return false; 
   //  } 


} 
?>
精彩图集

赞助商链接