"uploadimage", /* 执行上传图片的action名称 */ "imageFieldName" => "upfile", /* 提交的图片表单名称 */ "imageMaxSize" => 1024 * 1024 * 10, /* 上传大小限制,单位B */ "imageAllowFiles" => [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */ "imageCompressEnable" => true, /* 是否压缩图片,默认是true */ "imageCompressBorder" => 1600, /* 图片压缩最长边限制 */ "imageInsertAlign" => "none", /* 插入的图片浮动方式 */ "imageUrlPrefix" => "", /* 图片访问路径前缀 */ 'imagePathFormat' => '', // 涂鸦图片上传配置项 "scrawlActionName" => "uploadscrawl", /* 执行上传涂鸦的action名称 */ "scrawlFieldName" => "upfile", /* 提交的图片表单名称 */ 'scrawlPathFormat' => '', "scrawlMaxSize" => 1024 * 1024 * 10, /* 上传大小限制,单位B */ 'scrawlUrlPrefix' => '', 'scrawlInsertAlign' => 'none', /* 抓取远程图片配置 */ 'catcherLocalDomain' => ['127.0.0.1', 'localhost', 'img.baidu.com'], "catcherActionName" => "catchimage", /* 执行抓取远程图片的action名称 */ 'catcherFieldName' => 'source', 'catcherPathFormat' => '', 'catcherUrlPrefix' => '', 'catcherMaxSize' => 1024 * 1024 * 10, /* 上传大小限制,单位B */ 'catcherAllowFiles' => ['.png', '.jpg', '.jpeg', '.gif', '.bmp'], /* 上传视频配置 */ "videoActionName" => "uploadvideo", /* 执行上传视频的action名称 */ "videoFieldName" => "upfile", /* 提交的视频表单名称 */ 'videoPathFormat' => '', 'videoUrlPrefix' => '', 'videoMaxSize' => 1024 * 1024 * 100, /* 上传大小限制,单位B */ 'videoAllowFiles' => [".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg", ".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], // 上传音频配置 "audioActionName" => "audio", "audioFieldName" => "file", "audioUrlPrefix" => "", "audioMaxSize" => 1024 * 1024 * 100, /* 上传大小限制,单位B */ "audioAllowFiles" => ['.mp3'], /* 上传文件配置 */ "fileActionName" => "uploadfile", /* controller里,执行上传视频的action名称 */ 'fileFieldName' => 'upfile', 'filePathFormat' => '', 'fileUrlPrefix' => '', 'fileMaxSize' => 1024 * 1024 * 100, /* 上传大小限制,单位B */ 'fileAllowFiles' => [".flv", ".swf", ".zip", ".rar", ".xls", ".xlsx", ".wav", ".mp4", ".mp3", ".webm"], ]; public function index() { $file = $this->request->file('upfile'); $action = $this->request->get('action'); try { switch ($action) { case 'config': return json($this->editorConfig); case 'uploadimage': return $this->uploadFile($file, 'images', 'ueditor'); case 'uploadscrawl': return $this->uploadFile($file, 'images', 'ueditor_scrawl'); case 'uploadvideo': return $this->uploadFile($file, 'videos', 'ueditor'); case 'uploadfile': return $this->uploadFile($file, 'files', 'ueditor'); default: return json(['state' => '请求地址出错']); } } catch (UploadException | Exception $e) { return json(['state' => $e->getMessage()]); } } /** * 统一文件上传处理 */ protected function uploadFile($file, $category, $subdir) { $upload = new UploadLib($file); $attachment = $upload->upload($category, $subdir); return json([ "state" => "SUCCESS", 'url' => $attachment->path, 'fullurl' => cdnurl($attachment->path, true), 'title' => $attachment->name, ]); } }