controller.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. error_reporting(E_ERROR);
  6. header("Content-Type: text/html; charset=utf-8");
  7. $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("config.json")), true);
  8. $action = $_GET['action'];
  9. switch ($action) {
  10. case 'config':
  11. $result = json_encode($CONFIG);
  12. break;
  13. /* 上传图片 */
  14. case 'uploadimage':
  15. /* 上传涂鸦 */
  16. case 'uploadscrawl':
  17. /* 上传视频 */
  18. case 'uploadvideo':
  19. /* 上传文件 */
  20. case 'uploadfile':
  21. $result = include("action_upload.php");
  22. break;
  23. /* 列出图片 */
  24. case 'listimage':
  25. $result = include("action_list.php");
  26. break;
  27. /* 列出文件 */
  28. case 'listfile':
  29. $result = include("action_list.php");
  30. break;
  31. /* 抓取远程文件 */
  32. case 'catchimage':
  33. $result = include("action_crawler.php");
  34. break;
  35. default:
  36. $result = json_encode(array(
  37. 'state'=> '请求地址出错'
  38. ));
  39. break;
  40. }
  41. /* 输出结果 */
  42. if (isset($_GET["callback"])) {
  43. if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
  44. echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
  45. } else {
  46. echo json_encode(array(
  47. 'state'=> 'callback参数不合法'
  48. ));
  49. }
  50. } else {
  51. echo $result;
  52. }