12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- declare(strict_types=1);
- /**
- * +----------------------------------------------------------------------
- * | Ueditor编辑器后台控制器制器
- * +----------------------------------------------------------------------
- */
- namespace app\sys\controller;
- use think\App;
- use think\facade\Config;
- class Ckeditor extends Base
- {
- /**
- * 图片上传
- * @file upload_file 上传的文件
- * @param string $img_id 图片ipnut text id 默认值 picture
- * @param boolean $water 是否添加水印
- * @param boolean $thumb 是否制作缩略图
- * @param int $width 缩略图最大宽
- * @param int $height 缩略图最大高
- * @param bool $overwrite 生成缩略图后是否保存原图
- */
- public function uploadimg()
- {
- if ($this->request->isPost()) {
- $file = $this->request->file('upload');
- if ($file) {
- try {
- validate(
- [
- 'file' => [
- // 限制文件大小(单位b),这里限制为4M
- 'fileSize' => 4 * 1024 * 1024,
- // 限制文件后缀,多个后缀以英文逗号分割
- 'fileExt' => 'jpg,png,gif,jpeg,webp,jfif'
- ]
- ],
- [
- 'file.fileSize' => '文件太大',
- 'file.fileExt' => '不支持的文件后缀',
- ]
- )->check(['file' => $file]);
- $savename = \think\facade\Filesystem::disk('public')->putFile('/', $file);
- return json([
- 'uploaded' => 1,
- 'fileName' => basename($savename),
- 'url' => Config::get('filesystem.disks.public.url') . '/' . $savename
- ]);
- } catch (\think\exception\ValidateException $e) {
- $this->error($e->getMessage());
- return json([
- 'uploaded' => 1,
- 'error' => ['message'=>$e->getMessage()]
- ]);
- }
- } else {
- return json([
- 'uploaded' => 1,
- 'error' => ['message'=>'图片不能为空']
- ]);
- }
- }
- }
- }
|