controller.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. //header('Access-Control-Allow-Origin: http://www.baidu.com'); //设置http://www.baidu.com允许跨域访问
  3. //header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With'); //设置允许的跨域header
  4. //date_default_timezone_set("Asia/chongqing");
  5. date_default_timezone_set("Asia/Chongqing");
  6. error_reporting(E_ERROR);
  7. header("Content-Type: text/html; charset=utf-8");
  8. $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("config.json")), true);
  9. $action = $_GET['action'];
  10. switch ($action) {
  11. case 'config':
  12. $result = json_encode($CONFIG);
  13. break;
  14. /* 上传图片 */
  15. case 'uploadimage':
  16. /* 上传涂鸦 */
  17. case 'uploadscrawl':
  18. /* 上传视频 */
  19. case 'uploadvideo':
  20. /* 上传文件 */
  21. case 'uploadfile':
  22. $result = include("action_upload.php");
  23. break;
  24. /* 列出图片 */
  25. case 'listimage':
  26. $result = include("action_list.php");
  27. break;
  28. /* 列出文件 */
  29. case 'listfile':
  30. $result = include("action_list.php");
  31. break;
  32. /* 抓取远程文件 */
  33. case 'catchimage':
  34. $result = include("action_crawler.php");
  35. break;
  36. default:
  37. $result = json_encode(array(
  38. 'state'=> '请求地址出错'
  39. ));
  40. break;
  41. }
  42. /* 输出结果 */
  43. if (isset($_GET["callback"])) {
  44. if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
  45. echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
  46. } else {
  47. echo json_encode(array(
  48. 'state'=> 'callback参数不合法'
  49. ));
  50. }
  51. } else {
  52. echo $result;
  53. }