人人商城

bom.ctrl.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. $_W['page']['title'] = '检测文件BOM - 常用系统工具 - 系统管理';
  8. set_time_limit(0);
  9. load()->func('file');
  10. if (checksubmit('submit')) {
  11. $path = IA_ROOT;
  12. $trees = file_tree($path);
  13. $bomtree = array();
  14. foreach ($trees as $tree) {
  15. $tree = str_replace($path, '', $tree);
  16. $tree = str_replace('\\', '/', $tree);
  17. if (strexists($tree, '.php')) {
  18. $fname = $path . $tree;
  19. $fp = fopen($fname, 'r');
  20. if (!empty($fp)) {
  21. $bom = fread($fp, 3);
  22. fclose($fp);
  23. if ($bom == "\xEF\xBB\xBF") {
  24. $bomtree[] = $tree;
  25. }
  26. }
  27. }
  28. }
  29. cache_write(cache_system_key('bomtree'), $bomtree);
  30. }
  31. if (checksubmit('dispose')) {
  32. $trees = cache_load(cache_system_key('bomtree'));
  33. $path = IA_ROOT;
  34. if (is_array($trees)) {
  35. foreach ($trees as $tree) {
  36. $fname = $path . $tree;
  37. $string = file_get_contents($fname);
  38. $string = substr($string, 3);
  39. file_put_contents($fname, $string);
  40. @fclose($fp);
  41. }
  42. }
  43. cache_delete(cache_system_key('bomtree'));
  44. }
  45. template('system/bom');