zmr.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. //by bbs.33hao.com
  3. if (isset($_GET['dir'])){ //config the basedir
  4. $basedir=$_GET['dir'];
  5. }else{
  6. $basedir = '.';
  7. }
  8. $auto = 1;
  9. checkdir($basedir);
  10. function checkdir($basedir)
  11. {
  12. if ($dh = opendir($basedir)) {
  13. while (($file = readdir($dh)) !== false) {
  14. if ($file != '.' && $file != '..'){
  15. if (!is_dir($basedir."/".$file)) {
  16. echo "filename: $basedir/
  17. $file ".checkBOM("$basedir/$file")." <br>";
  18. }else{
  19. $dirname = $basedir."/".
  20. $file;
  21. checkdir($dirname);
  22. }
  23. }
  24. }
  25. closedir($dh);
  26. }
  27. }
  28. function checkBOM ($filename) {
  29. global $auto;
  30. $contents = file_get_contents($filename);
  31. $charset[1] = substr($contents, 0, 1);
  32. $charset[2] = substr($contents, 1, 1);
  33. $charset[3] = substr($contents, 2, 1);
  34. if (ord($charset[1]) == 239 && ord($charset[2]) == 187 &&
  35. ord($charset[3]) == 191) {
  36. if ($auto == 1) {
  37. $rest = substr($contents, 3);
  38. rewrite ($filename, $rest);
  39. return ("<font color=red>BOM found,
  40. automatically removed.</font>");
  41. } else {
  42. return ("<font color=red>BOM found.
  43. </font>");
  44. }
  45. }
  46. else return ("BOM Not Found.");
  47. }
  48. function rewrite ($filename, $data) {
  49. $filenum = fopen($filename, "w");
  50. flock($filenum, LOCK_EX);
  51. fwrite($filenum, $data);
  52. fclose($filenum);
  53. }
  54. ?>