SystemAttachment.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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 service\UploadService as Upload;
  6. /**
  7. * 附件管理控制器
  8. * Class SystemAttachment
  9. * @package app\admin\controller\system
  10. *
  11. */
  12. class SystemAttachment extends AuthController
  13. {
  14. /**
  15. * 编辑器上传图片
  16. * @return \think\response\Json
  17. */
  18. public function upload()
  19. {
  20. $res = Upload::image('upfile','editor/'.date('Ymd'));
  21. if($res->status==false && $res->error){
  22. exit(json_encode(['state'=>$res->error]));
  23. }
  24. //产品图片上传记录
  25. $fileInfo = $res->fileInfo->getinfo();
  26. $thumbPath = Upload::thumb($res->dir);
  27. SystemAttachmentModel::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,$thumbPath,0);
  28. $info = array(
  29. "originalName" => $fileInfo['name'],
  30. "name" => $res->fileInfo->getSaveName(),
  31. "url" => '.'.$res->dir,
  32. "size" => $fileInfo['size'],
  33. "type" => $fileInfo['type'],
  34. "state" => "SUCCESS"
  35. );
  36. echo json_encode($info);
  37. }
  38. }