action_upload.php 2.4 KB

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