action_upload.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if (defined('STATIC_DIR')) {
  49. $config['pathFormat'] = STATIC_DIR . $config['pathFormat'];
  50. }
  51. /* 生成上传实例对象并完成上传 */
  52. $up = new Uploader($fieldName, $config, $base64);
  53. // 图片打水印
  54. $rs = $up->getFileInfo();
  55. $ext = array(
  56. '.jpg',
  57. '.png',
  58. '.gif'
  59. );
  60. if (in_array($rs['type'], $ext)) {
  61. resize_img(ROOT_PATH . $rs['url']); // 缩放大小
  62. watermark_img(ROOT_PATH . $rs['url']); // 水印
  63. }
  64. /**
  65. * 得到上传文件所对应的各个参数,数组结构
  66. * array(
  67. * "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
  68. * "url" => "", //返回的地址
  69. * "title" => "", //新文件名
  70. * "original" => "", //原始文件名
  71. * "type" => "" //文件类型
  72. * "size" => "", //文件大小
  73. * )
  74. */
  75. /* 返回数据 */
  76. return json_encode($up->getFileInfo());