SystemAttachment.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. SystemAttachmentModel::attachmentAdd($res->fileInfo->getSaveName(),$fileInfo['size'],$fileInfo['type'],$res->dir,'',0);
  27. $info = array(
  28. "originalName" => $fileInfo['name'],
  29. "name" => $res->fileInfo->getSaveName(),
  30. "url" => '.'.$res->dir,
  31. "size" => $fileInfo['size'],
  32. "type" => $fileInfo['type'],
  33. "state" => "SUCCESS"
  34. );
  35. echo json_encode($info);
  36. }
  37. }