action_upload.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * 上传附件和上传视频
  4. * User: Jinqn
  5. * Date: 14-04-09
  6. * Time: 上午10:17
  7. */
  8. include "Uploader.class.php";
  9. /* 上传配置 */
  10. $base64 = "upload";
  11. switch (htmlspecialchars($_GET['action'])) {
  12. case 'uploadimage':
  13. $config = array(
  14. "pathFormat" => $CONFIG['imagePathFormat'],
  15. "maxSize" => $CONFIG['imageMaxSize'],
  16. "allowFiles" => $CONFIG['imageAllowFiles']
  17. );
  18. $fieldName = $CONFIG['imageFieldName'];
  19. break;
  20. case 'uploadscrawl':
  21. $config = array(
  22. "pathFormat" => $CONFIG['scrawlPathFormat'],
  23. "maxSize" => $CONFIG['scrawlMaxSize'],
  24. "allowFiles" => $CONFIG['scrawlAllowFiles'],
  25. "oriName" => "scrawl.png"
  26. );
  27. $fieldName = $CONFIG['scrawlFieldName'];
  28. $base64 = "base64";
  29. break;
  30. case 'uploadvideo':
  31. $config = array(
  32. "pathFormat" => $CONFIG['videoPathFormat'],
  33. "maxSize" => $CONFIG['videoMaxSize'],
  34. "allowFiles" => $CONFIG['videoAllowFiles']
  35. );
  36. $fieldName = $CONFIG['videoFieldName'];
  37. break;
  38. case 'uploadfile':
  39. default:
  40. $config = array(
  41. "pathFormat" => $CONFIG['filePathFormat'],
  42. "maxSize" => $CONFIG['fileMaxSize'],
  43. "allowFiles" => $CONFIG['fileAllowFiles']
  44. );
  45. $fieldName = $CONFIG['fileFieldName'];
  46. break;
  47. }
  48. /* 生成上传实例对象并完成上传 */
  49. $up = new Uploader($fieldName, $config, $base64);
  50. /**
  51. * 得到上传文件所对应的各个参数,数组结构
  52. * array(
  53. * "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
  54. * "url" => "", //返回的地址
  55. * "title" => "", //新文件名
  56. * "original" => "", //原始文件名
  57. * "type" => "" //文件类型
  58. * "size" => "", //文件大小
  59. * )
  60. */
  61. /* 返回数据 */
  62. return json_encode($up->getFileInfo());