天天看点

php删除文件夹及其下面的文件

php删除文件:unlink()函数

<?php 

echo unlink('test.doc'); 

?> 

php删除文件夹及其下面的文件:

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; 

      本文转自许琴 51CTO博客,原文链接:http://blog.51cto.com/xuqin/1130186,如需转载请自行联系原作者