action_upload.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. $sellerid = isset($_GET['sellerid']) ? intval($_GET['sellerid']) : 0;
  19. if($sellerid > 0)
  20. {
  21. $config['pathFormat'] = "/Uploads/image/goods_description/{$sellerid}/{yyyy}{mm}{dd}/{time}{rand:6}";
  22. }
  23. $fieldName = $CONFIG['imageFieldName'];
  24. break;
  25. case 'uploadscrawl':
  26. $config = array(
  27. "pathFormat" => $CONFIG['scrawlPathFormat'],
  28. "maxSize" => $CONFIG['scrawlMaxSize'],
  29. "allowFiles" => $CONFIG['scrawlAllowFiles'],
  30. "oriName" => "scrawl.png"
  31. );
  32. $fieldName = $CONFIG['scrawlFieldName'];
  33. $base64 = "base64";
  34. break;
  35. case 'uploadvideo':
  36. $config = array(
  37. "pathFormat" => $CONFIG['videoPathFormat'],
  38. "maxSize" => $CONFIG['videoMaxSize'],
  39. "allowFiles" => $CONFIG['videoAllowFiles']
  40. );
  41. $fieldName = $CONFIG['videoFieldName'];
  42. break;
  43. case 'uploadfile':
  44. default:
  45. $config = array(
  46. "pathFormat" => $CONFIG['filePathFormat'],
  47. "maxSize" => $CONFIG['fileMaxSize'],
  48. "allowFiles" => $CONFIG['fileAllowFiles']
  49. );
  50. $fieldName = $CONFIG['fileFieldName'];
  51. break;
  52. }
  53. /* 生成上传实例对象并完成上传 */
  54. $up = new Uploader($fieldName, $config, $base64);
  55. /**
  56. * 得到上传文件所对应的各个参数,数组结构
  57. * array(
  58. * "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
  59. * "url" => "", //返回的地址
  60. * "title" => "", //新文件名
  61. * "original" => "", //原始文件名
  62. * "type" => "" //文件类型
  63. * "size" => "", //文件大小
  64. * )
  65. */
  66. /* 返回数据 */
  67. return json_encode($up->getFileInfo());