controller.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Ueditor 事件处理方法
  4. *
  5. * @author widuu <admin@widuu.com>
  6. * @document https://github.com/widuu/qiniu_ueditor_1.4.3
  7. */
  8. /**
  9. * 设置http://www.widuu.com允许跨域访问
  10. * header('Access-Control-Allow-Origin: http://www.baidu.com');
  11. * header('Access-Control-Allow-Headers: X-Requested-With,X_Requested_With');
  12. */
  13. date_default_timezone_set("Asia/chongqing");
  14. error_reporting(E_ERROR);
  15. header("Content-Type: text/html; charset=utf-8");
  16. define('DS', DIRECTORY_SEPARATOR);
  17. define('UEDITOR_PATH', dirname($_SERVER['SCRIPT_FILENAME']) . DS);
  18. // 注册函数方法
  19. spl_autoload_register(function($class){
  20. if( strpos(strtolower($class), "driver") ){
  21. $class_path = UEDITOR_PATH . 'vendor'. DS .'driver'. DS . $class. '.class.php';
  22. }else{
  23. $class_path = UEDITOR_PATH . 'vendor'. DS . $class. '.class.php';
  24. }
  25. if( file_exists($class_path) ){
  26. include_once($class_path);
  27. }else{
  28. return array(
  29. 'state' => 'ERROR',
  30. 'error' => $class.' not exists'
  31. );
  32. }
  33. });
  34. // php 配置信息
  35. $config = require_once( UEDITOR_PATH.'config.php' );
  36. // 获取方法
  37. $action = !empty($_GET['action']) ? trim($_GET['action']) : '';
  38. // 实例化处理方法
  39. $handle = new Channel($config);
  40. // 运行
  41. $response = $handle->dispatcher($action);
  42. $result = json_encode($response);
  43. /* 输出结果 */
  44. if (isset($_GET["callback"])) {
  45. if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
  46. echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
  47. } else {
  48. echo json_encode(array(
  49. 'state'=> 'callback参数不合法'
  50. ));
  51. }
  52. } else {
  53. echo $result;
  54. }
  55. exit();