common.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * 判断语言
  4. */
  5. function lang(){
  6. $lang = $_REQUEST['lang'] ? $_REQUEST['lang'] :"zh";
  7. return include("lang.".$lang.".php");
  8. }
  9. function L($field){
  10. if (!isset($GLOBALS['lang'])) {
  11. $GLOBALS['lang'] = lang();
  12. }
  13. return $GLOBALS['lang'][$field] ;
  14. }
  15. /**
  16. * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
  17. *
  18. * @param string $file 文件/目录
  19. * @return boolean
  20. */
  21. function new_is_writeable($file) {
  22. if (is_dir($file)){
  23. $dir = $file;
  24. if ($fp = @fopen("$dir/test.txt", 'w')) {
  25. @fclose($fp);
  26. @unlink("$dir/test.txt");
  27. $writeable = 1;
  28. } else {
  29. $writeable = 0;
  30. }
  31. } else {
  32. if ($fp = @fopen($file, 'a+')) {
  33. @fclose($fp);
  34. $writeable = 1;
  35. } else {
  36. $writeable = 0;
  37. }
  38. }
  39. return $writeable;
  40. }
  41. function clear_runtime($path = "../Application/Runtime"){
  42. //给定的目录不是一个文件夹
  43. if(!is_dir($path)){
  44. return null;
  45. }
  46. $fh = opendir($path);
  47. while(($row = readdir($fh)) !== false){
  48. //过滤掉虚拟目录
  49. if($row == '.' || $row == '..'|| $row == 'index.html'){
  50. continue;
  51. }
  52. if(!is_dir($path.'/'.$row)){
  53. unlink($path.'/'.$row);
  54. }
  55. clear_runtime($path.'/'.$row);
  56. }
  57. //关闭目录句柄,否则出Permission denied
  58. closedir($fh);
  59. return true;
  60. }
  61. function ajax_out($message,$error_code = 0){
  62. echo json_encode(array("error_code"=>$error_code,"message"=>$message));
  63. exit();
  64. }