php删除文件:unlink()函数

 
  
  1. <?php 
  2. echo unlink('test.doc'); 
  3. ?> 

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

 
  
  1. function deldir($dir) { 
  2.   //先删除目录下的文件: 
  3.   $dh=opendir($dir); 
  4.   while ($file=readdir($dh)) { 
  5.     if($file!="." && $file!="..") { 
  6.       $fullpath=$dir."/".$file
  7.       if(!is_dir($fullpath)) { 
  8.           unlink($fullpath); 
  9.       } else { 
  10.           deldir($fullpath); 
  11.       } 
  12.     } 
  13.   } 
  14.   
  15.   closedir($dh); 
  16.   //删除当前文件夹: 
  17.   if(rmdir($dir)) { 
  18.     return true; 
  19.   } else { 
  20.     return false; 
  21.   }