php递归删除目录所有文件

  1. <meta http-equiv="content-type" content="text/html; charset=gb2312">
  2. <?php
  3. function tree($directory)
  4. {
  5. $mydir=dir($directory);
  6. echo "<ul> ";
  7. while($file=$mydir->read()){
  8. if((is_dir("$directory/$file")) and ($file!=".") and ($file!=".."))
  9. {echo "<li><font color="#ff00cc"><b>$file</b></font></li> ";
  10. tree("$directory/$file");
  11. }
  12. else{//开源代码phpfensi.com
  13. $a = explode('.',$file);
  14. if($a[1] == 'html' || $a[1] == 'htm')
  15. {
  16. //unlink($file);
  17. echo "<li>$file</li> ";
  18. }
  19. }
  20. }
  21. echo "</ul> ";
  22. $mydir->close();
  23. }
  24. //开始运行
  25. echo "<h2>目录为粉红色</h2><br> ";
  26. tree("./");
  27. ?>