SystemAttachment.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\model\system\SystemAttachment as SystemAttachmentModel;
  4. use app\admin\controller\AuthController;
  5. use crmeb\services\upload\Upload;
  6. /**
  7. * 附件管理控制器
  8. * Class SystemAttachment
  9. * @package app\admin\controller\system
  10. *
  11. */
  12. class SystemAttachment extends AuthController
  13. {
  14. /**
  15. * TODO 编辑器上传图片
  16. */
  17. public function upload()
  18. {
  19. $uploadType = (int)sys_config('upload_type', 1);
  20. $upload = new Upload($uploadType, [
  21. 'accessKey' => sys_config('accessKey'),
  22. 'secretKey' => sys_config('secretKey'),
  23. 'uploadUrl' => sys_config('uploadUrl'),
  24. 'storageName' => sys_config('storage_name'),
  25. 'storageRegion' => sys_config('storage_region'),
  26. ]);
  27. $resInfo = $upload->to('editor/' . date('Ymd'))->validate()->move('upfile');
  28. if ($resInfo === false) {
  29. echo json_encode([
  30. 'msg' => $upload->getError(),
  31. 'state' => 'ERROR'
  32. ]);
  33. } else {
  34. $res = $upload->getUploadInfo();
  35. $res['image_type'] = $uploadType;
  36. SystemAttachmentModel::attachmentAdd($res['name'], $res['size'], $res['type'], $res['dir'], $res['thumb_path'], 0, $res['image_type'], $res['time']);
  37. $info["originalName"] = $res['name'];
  38. $info["name"] = $res['name'];
  39. $info["url"] = $res['dir'];
  40. $info["size"] = $res['size'];
  41. $info["type"] = $res['type'];
  42. $info["state"] = "SUCCESS";
  43. if ($res['image_type'] == 1) $info['url'] = sys_config('site_url') . str_replace('\\', '/', $res['dir']);
  44. echo json_encode($info);
  45. }
  46. }
  47. }