123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?php
- namespace App\Services\Ueditor;
- class UploadAction
- {
- protected $config;
- protected $action;
- public function __construct($config, $action)
- {
- $this->config = $config;
- $this->action = $action;
- }
- public function doUpload()
- {
- /* 上传配置 */
- $base64 = "upload";
- switch (htmlspecialchars($this->action)) {
- case 'uploadimage':
- $config = array(
- "pathFormat" => $this->config['imagePathFormat'],
- "maxSize" => $this->config['imageMaxSize'],
- "allowFiles" => $this->config['imageAllowFiles']
- );
- $fieldName = $this->config['imageFieldName'];
- break;
- case 'uploadscrawl':
- $config = array(
- "pathFormat" => $this->config['scrawlPathFormat'],
- "maxSize" => $this->config['scrawlMaxSize'],
- "allowFiles" => $this->config['scrawlAllowFiles'],
- "oriName" => "scrawl.png"
- );
- $fieldName = $this->config['scrawlFieldName'];
- $base64 = "base64";
- break;
- case 'uploadvideo':
- $config = array(
- "pathFormat" => $this->config['videoPathFormat'],
- "maxSize" => $this->config['videoMaxSize'],
- "allowFiles" => $this->config['videoAllowFiles']
- );
- $fieldName = $this->config['videoFieldName'];
- break;
- case 'uploadfile':
- default:
- $config = array(
- "pathFormat" => $this->config['filePathFormat'],
- "maxSize" => $this->config['fileMaxSize'],
- "allowFiles" => $this->config['fileAllowFiles']
- );
- $fieldName = $this->config['fileFieldName'];
- break;
- }
- /* 生成上传实例对象并完成上传 */
- $up = new UploaderService($fieldName, $config, $base64);
- /**
- * 得到上传文件所对应的各个参数,数组结构
- * array(
- * "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
- * "url" => "", //返回的地址
- * "title" => "", //新文件名
- * "original" => "", //原始文件名
- * "type" => "" //文件类型
- * "size" => "", //文件大小
- * )
- */
- /* 返回数据 */
- return json_encode($up->getFileInfo());
- }
- }
|