diff --git a/app/api/controller/Index.php b/app/api/controller/Index.php index b8693f4..0bf03d0 100644 --- a/app/api/controller/Index.php +++ b/app/api/controller/Index.php @@ -17,80 +17,104 @@ use think\facade\Session; class Index extends BaseController { //上传文件 - public function upload() - { - $param = get_params(); - if (request()->file('file')) { - $file = request()->file('file'); - } else { - return to_assign(1, '没有选择上传文件'); - } - // dump($file);die; - // 获取上传文件的hash散列值 - $sha1 = $file->hash('sha1'); - $md5 = $file->hash('md5'); - $rule = [ - 'image' => 'jpg,png,jpeg,gif', - 'doc' => 'doc,docx,ppt,pptx,xls,xlsx,pdf', - 'file' => 'zip,gz,7z,rar,tar', - ]; - $fileExt = $rule['image'] . ',' . $rule['doc'] . ',' . $rule['file']; - //1M=1024*1024=1048576字节 - $fileSize = 2 * 1024 * 1024; - if (isset($param['type']) && $param['type']) { - $fileExt = $rule[$param['type']]; - } - if (isset($param['size']) && $param['size']) { - $fileSize = $param['size']; - } - $validate = \think\facade\Validate::rule([ - 'image' => 'require|fileSize:' . $fileSize . '|fileExt:' . $fileExt, - ]); - $file_check['image'] = $file; - if (!$validate->check($file_check)) { - return to_assign(1, $validate->getError()); - } - // 日期前綴 - $dataPath = date('Ym'); - $use = 'thumb'; - $filename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file, function () use ($md5) { - return $md5; - }); - if ($filename) { - //写入到附件表 - $data = []; - $path = get_config('filesystem.disks.public.url'); - $data['filepath'] = $path . '/' . $filename; - $data['name'] = $file->getOriginalName(); - $data['mimetype'] = $file->getOriginalMime(); - $data['fileext'] = $file->extension(); - $data['filesize'] = $file->getSize(); - $data['filename'] = $filename; - $data['sha1'] = $sha1; - $data['md5'] = $md5; - $data['module'] = \think\facade\App::initialize()->http->getName(); - $data['action'] = app('request')->action(); - $data['uploadip'] = app('request')->ip(); - $data['create_time'] = time(); - $data['user_id'] = $this->uid; - if ($data['module'] = 'admin') { - //通过后台上传的文件直接审核通过 - $data['status'] = 1; - $data['admin_id'] = $data['user_id']; - $data['audit_time'] = time(); - } - $data['use'] = request()->has('use') ? request()->param('use') : $use; //附件用处 - $res['id'] = Db::name('file')->insertGetId($data); - $res['filepath'] = $data['filepath']; - $res['name'] = $data['name']; - $res['filename'] = $data['filename']; - $res['filesize'] = $data['filesize']; - add_log('upload', $data['user_id'], $data); - return to_assign(0, '上传成功', $res); - } else { - return to_assign(1, '上传失败,请重试'); - } - } + public function upload() + { + $param = get_params(); + //var_dump($param);exit; + $sourse = 'file'; + if(isset($param['sourse'])){ + $sourse = $param['sourse']; + } + if($sourse == 'file' || $sourse == 'tinymce'){ + if(request()->file('file')){ + $file = request()->file('file'); + } + else{ + return to_assign(1, '没有选择上传文件'); + } + } + else{ + if (request()->file('editormd-image-file')) { + $file = request()->file('editormd-image-file'); + } else { + return to_assign(1, '没有选择上传文件'); + } + } + // 获取上传文件的hash散列值 + $sha1 = $file->hash('sha1'); + $md5 = $file->hash('md5'); + $rule = [ + 'image' => 'jpg,png,jpeg,gif', + 'doc' => 'doc,docx,ppt,pptx,xls,xlsx,pdf', + 'file' => 'zip,gz,7z,rar,tar', + ]; + $fileExt = $rule['image'] . ',' . $rule['doc'] . ',' . $rule['file']; + //1M=1024*1024=1048576字节 + $fileSize = 2 * 1024 * 1024; + if (isset($param['type']) && $param['type']) { + $fileExt = $rule[$param['type']]; + } + if (isset($param['size']) && $param['size']) { + $fileSize = $param['size']; + } + $validate = \think\facade\Validate::rule([ + 'image' => 'require|fileSize:' . $fileSize . '|fileExt:' . $fileExt, + ]); + $file_check['image'] = $file; + if (!$validate->check($file_check)) { + return to_assign(1, $validate->getError()); + } + // 日期前綴 + $dataPath = date('Ym'); + $use = 'thumb'; + $filename = \think\facade\Filesystem::disk('public')->putFile($dataPath, $file, function () use ($md5) { + return $md5; + }); + if ($filename) { + //写入到附件表 + $data = []; + $path = get_config('filesystem.disks.public.url'); + $data['filepath'] = $path . '/' . $filename; + $data['name'] = $file->getOriginalName(); + $data['mimetype'] = $file->getOriginalMime(); + $data['fileext'] = $file->extension(); + $data['filesize'] = $file->getSize(); + $data['filename'] = $filename; + $data['sha1'] = $sha1; + $data['md5'] = $md5; + $data['module'] = \think\facade\App::initialize()->http->getName(); + $data['action'] = app('request')->action(); + $data['uploadip'] = app('request')->ip(); + $data['create_time'] = time(); + $data['user_id'] = get_login_admin('id') ? get_login_admin('id') : 0; + if ($data['module'] = 'admin') { + //通过后台上传的文件直接审核通过 + $data['status'] = 1; + $data['admin_id'] = $data['user_id']; + $data['audit_time'] = time(); + } + $data['use'] = request()->has('use') ? request()->param('use') : $use; //附件用处 + $res['id'] = Db::name('file')->insertGetId($data); + $res['filepath'] = $data['filepath']; + $res['name'] = $data['name']; + $res['filename'] = $data['filename']; + add_log('upload', $data['user_id'], $data); + if($sourse == 'editormd'){ + //editormd编辑器上传返回 + return json(['success'=>1,'message'=>'上传成功','url'=>$data['filepath']]); + } + else if($sourse == 'tinymce'){ + //tinymce编辑器上传返回 + return json(['success'=>1,'message'=>'上传成功','location'=>$data['filepath']]); + } + else{ + //普通上传返回 + return to_assign(0, '上传成功', $res); + } + } else { + return to_assign(1, '上传失败,请重试'); + } + } //清空缓存 public function cache_clear() diff --git a/app/article/controller/Index.php b/app/article/controller/Index.php index 98f7e71..21f8a6d 100644 --- a/app/article/controller/Index.php +++ b/app/article/controller/Index.php @@ -168,6 +168,7 @@ class Index extends BaseController { $id = get_params("id"); $detail = (new ArticleList())->detail($id); + $detail['cate_title'] = Db::name('ArticleCate')->where(['id' => $detail['article_cate_id']])->value('title'); // read 字段加 1 Db::name('article')->where('id', $id)->inc('read')->update(); View::assign('detail', $detail); diff --git a/app/article/view/index/add.html b/app/article/view/index/add.html index 7eecb19..a92be35 100644 --- a/app/article/view/index/add.html +++ b/app/article/view/index/add.html @@ -1,14 +1,14 @@ {extend name="../../base/view/common/base" /} {block name="body"} -