diff --git a/app/admin/controller/Admin.php b/app/admin/controller/Admin.php index 5360b02..1f8037e 100644 --- a/app/admin/controller/Admin.php +++ b/app/admin/controller/Admin.php @@ -70,7 +70,7 @@ class Admin extends AuthController $form = array(); $form[] = Elm::input('username', '登录账号')->col(10); $form[] = Elm::input('nickname', '昵称')->col(10); - $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/images/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::password('password', '密码')->col(10); $form[] = Elm::input('realname', '真实姓名')->col(10); $form[] = Elm::select('role_id', '角色')->options(function () { @@ -102,7 +102,7 @@ class Admin extends AuthController $form = array(); $form[] = Elm::input('username', '登录账号', $ainfo['username'])->col(10); $form[] = Elm::input('nickname', '昵称', $ainfo['nickname'])->col(10); - $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/images/index', array('fodder' => 'avatar', 'limit' => 1)), $ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)), $ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::password('password', '密码', $ainfo['password'])->col(10); $form[] = Elm::input('realname', '真实姓名', $ainfo['realname'])->col(10); $form[] = Elm::select('role_id', '角色', $ainfo['role_id'])->options(function () { diff --git a/app/admin/controller/Advert.php b/app/admin/controller/Advert.php index 5cb6128..0ebb51a 100644 --- a/app/admin/controller/Advert.php +++ b/app/admin/controller/Advert.php @@ -74,7 +74,7 @@ class Advert extends AuthController $form = array(); $form[] = Elm::input('title', '广告名称')->col(10); $form[] = Elm::input('url', '链接地址')->col(10); - $form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('admin/images/index', array('fodder' => 'cover_path', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('admin/image/index', array('fodder' => 'cover_path', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::input('sort', '排序')->col(10); $form[] = Elm::select('position', '位置')->options(function () { $options = []; @@ -102,7 +102,7 @@ class Advert extends AuthController $form = array(); $form[] = Elm::input('title', '广告名称', $info['title'])->col(10); $form[] = Elm::input('url', '链接地址', $info['url'])->col(10); - $form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('admin/images/index', array('fodder' => 'cover_path', 'limit' => 1)), $info['cover_path'])->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('cover_path', '广告图片', Url::buildUrl('admin/image/index', array('fodder' => 'cover_path', 'limit' => 1)), $info['cover_path'])->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::input('sort', '排序', $info['sort'])->col(10); $form[] = Elm::select('position', '位置', $info['position'])->options(function () { $options = []; diff --git a/app/admin/controller/Files.php b/app/admin/controller/File.php similarity index 70% rename from app/admin/controller/Files.php rename to app/admin/controller/File.php index cafbc81..904f70f 100644 --- a/app/admin/controller/Files.php +++ b/app/admin/controller/File.php @@ -13,7 +13,7 @@ use think\exception\ValidateException; use think\facade\Filesystem; use think\Request; -class Files extends AuthController +class File extends AuthController { /** * 单个图片上传 @@ -25,24 +25,25 @@ class Files extends AuthController public function image() { $file = $this->request->file("file"); + $fileType = "image"; $storage_type = system_config("storage_type") ?: 1;//默认未本地存储 switch ($storage_type) { case 1: - $savename = Filesystem::putFile('images', $file); - $filePath = "/uploads/" . $savename; + $saveName = Filesystem::putFile($fileType, $file); + $filePath = Filesystem::url($saveName); //转换因为win导致的兼容问题 if(strtoupper(substr(PHP_OS,0,3))==='WIN'){ $filePath = str_replace( DIRECTORY_SEPARATOR, '/',$filePath); } break; case 2: - $savename = Filesystem::putFile('images', $file); + $saveName = Filesystem::putFile('image', $file); $ext = $file->getOriginalExtension(); $key = '/image/' . date('Ymd') . "/" . substr(md5($file->getRealPath()), 0, 5) . date('YmdHis') . rand(0, 9999) . '.' . $ext; $filePath = QcloudCoService::put($key, $file->getRealPath()); break; } - return Attachment::addAttachment($this->request->param("cid", 0), $savename, $filePath, 'images', $file->getMime(), $file->getSize(), $storage_type) ? app("json")->code()->success("上传成功", ['filePath' => $filePath, "name" => $savename]) : app("json")->fail("上传失败"); + return Attachment::addAttachment($this->request->param("cid", 0), $saveName, $filePath, 'image', $file->getMime(), $file->getSize(), $storage_type) ? app("json")->code()->success("上传成功", ['filePath' => $filePath, "name" => $saveName]) : app("json")->fail("上传失败"); } /** @@ -55,37 +56,24 @@ class Files extends AuthController ['image', ''] ]); if ($data['image'] == '') return app("json")->fail("上传失败,没有文件"); - $path = "uploads/image/" . date("Ymd") . '/'; + $path = "upload/image/" . date("Ymd") . '/'; if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $data['image'], $result)) { $type = $result[2]; if (!file_exists($path)) mkdir($path, 0755, true); - $savename = $path . md5(time()) . ".{$type}"; + $saveName = $path . md5(time()) . ".{$type}"; //转换因为win导致的兼容问题 if(strtoupper(substr(PHP_OS,0,3))==='WIN'){ - $savename = str_replace( DIRECTORY_SEPARATOR, '/',$savename); + $saveName = str_replace( DIRECTORY_SEPARATOR, '/',$saveName); } - if (file_put_contents($savename, base64_decode(str_replace($result[1], '', $data['image'])))) return app("json")->success("上传成功", ['src' => "/" . $savename]); + if (file_put_contents($saveName, base64_decode(str_replace($result[1], '', $data['image'])))) return app("json")->success("上传成功", ['src' => "/" . $saveName]); else return app("json")->fail("上传失败,写入文件失败!"); } else return app("json")->fail("上传失败,图片格式有误!"); } - /** - * tinymec - * @return mixed - */ - public function tinymce() - { - $filePath = Filesystem::putFile('image', request()->file('file')); - if(strtoupper(substr(PHP_OS,0,3))==='WIN'){ - $filePath = str_replace( DIRECTORY_SEPARATOR, '/',$filePath); - } - return json_encode(['location' => "/uploads/" . $filePath]); - } - /** * @单文件上传 - * @param string $type 类型 files images documents banners + * @param string $type 类型 files image documents banners * @return mixed */ public function upload(Request $request) @@ -93,18 +81,17 @@ class Files extends AuthController if ($request->isPost()) { // 获取表单上传文件 例如上传了001.jpg $file = $this->request->file('file');//根据表单name替换imgFile - $type = $this->request->post("type"); - $type = $type ?: 'files'; - switch ($type) { - case 'files': + $fileType = $this->request->post("type")?:'file'; + switch ($fileType) { + case 'file': $fileSize = 10 * 1024 * 1024; $fileExt = 'pdf,doc,docx,png,jpeg,jpg,text,mp4'; break; - case 'slides': + case 'slide': $fileSize = 10 * 1024 * 1024; $fileExt = 'png,jpeg,jpg'; break; - case 'documents': + case 'document': $fileSize = 5 * 1024 * 1024; $fileExt = 'pdf,doc,docx'; break; @@ -112,16 +99,12 @@ class Files extends AuthController $fileSize = 5 * 1024 * 1024; $fileExt = 'png,jpeg,jpg'; break; - case 'images': - $fileSize = 5 * 1024 * 1024; - $fileExt = 'png,jpeg,jpg'; - break; case 'avatar': $fileSize = 4 * 1024 * 1024; $fileExt = 'png,jpeg,jpg'; break; default: - $fileSize = 0 * 1024 * 1024; + $fileSize = 10 * 1024 * 1024; $fileExt = 'pdf,doc,docx'; break; } @@ -134,13 +117,13 @@ class Files extends AuthController 'fileExt' => $fileExt // 更多规则请看“上传验证”的规则,文档地址https://www.kancloud.cn/manual/thinkphp6_0/1037629#_444 ]])->check(['file' => $file]); - $savename = Filesystem::putFile($type, $file); - $filePath = "/uploads/" . $savename; + $saveName = Filesystem::putFile($fileType, $file); + $filePath = Filesystem::url($saveName); //转换因为win导致的兼容问题 if(strtoupper(substr(PHP_OS,0,3))==='WIN'){ $filePath = str_replace( DIRECTORY_SEPARATOR, '/',$filePath); } - return $savename ? app("json")->code()->success("上传成功", ['filePath' => $filePath, "name" => basename($savename)]) : app("json")->fail("上传失败"); + return $saveName ? app("json")->code()->success("上传成功", ['filePath' => $filePath, "name" => basename($saveName)]) : app("json")->fail("上传失败"); } catch (ValidateException $e) { return app("json")->fail($e->getMessage()); } diff --git a/app/admin/controller/FriendLink.php b/app/admin/controller/FriendLink.php index 6856d8c..666cb56 100644 --- a/app/admin/controller/FriendLink.php +++ b/app/admin/controller/FriendLink.php @@ -66,7 +66,7 @@ class FriendLink extends AuthController $form = array(); $form[] = Elm::input('title', '链接名称')->col(10); $form[] = Elm::input('url', '链接地址')->col(10); - $form[] = Elm::frameImage('image', '网站图标', Url::buildUrl('admin/images/index', array('fodder' => 'image', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('image', '网站图标', Url::buildUrl('admin/image/index', array('fodder' => 'image', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::input('sort', '排序')->col(10); $form[] = Elm::textarea('description', '描述')->col(10); $form[] = Elm::radio('status', '状态', 1)->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10); @@ -88,7 +88,7 @@ class FriendLink extends AuthController $form = array(); $form[] = Elm::input('title', '链接名称', $ainfo['title'])->col(10); $form[] = Elm::input('url', '链接地址', $ainfo['url'])->col(10); - $form[] = Elm::frameImage('image', '网站图标', Url::buildUrl('admin/images/index', array('fodder' => 'image', 'limit' => 1)), $ainfo['image'])->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('image', '网站图标', Url::buildUrl('admin/image/index', array('fodder' => 'image', 'limit' => 1)), $ainfo['image'])->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::input('sort', '排序', $ainfo['sort'])->col(10); $form[] = Elm::textarea('description', '描述', $ainfo['description'])->col(10); $form[] = Elm::radio('status', '状态', $ainfo['status'])->options([['label' => '启用', 'value' => 1], ['label' => '冻结', 'value' => 0]])->col(10); diff --git a/app/admin/controller/Images.php b/app/admin/controller/Image.php similarity index 91% rename from app/admin/controller/Images.php rename to app/admin/controller/Image.php index 78f560d..7ebfa65 100644 --- a/app/admin/controller/Images.php +++ b/app/admin/controller/Image.php @@ -18,13 +18,13 @@ use think\db\exception\ModelNotFoundException; * Class Images * @package app\admin\controller\widget */ -class Images extends AuthController +class Image extends AuthController { /** * 附件类型 * @var string */ - private $type = "images"; + private $type = "image"; public function index() { @@ -39,7 +39,7 @@ class Images extends AuthController */ public function category() { - return app("json")->success(AttachmentCategory::buildNodes("images", 0, $this->request->param("title", ""))); + return app("json")->success(AttachmentCategory::buildNodes("image", 0, $this->request->param("title", ""))); } /** @@ -60,7 +60,7 @@ class Images extends AuthController return $menu; })->col(18); $form[] = Elm::input('name', '分类名称')->col(18); - $form[] = Elm::hidden('type', 'images')->col(18); + $form[] = Elm::hidden('type', $this->type)->col(18); $form = Form::make_post_form($form, url('saveCategory')->build()); $this->assign(compact('form')); return $this->fetch("public/form-builder"); @@ -85,7 +85,7 @@ class Images extends AuthController return $menu; })->col(18); $form[] = Elm::input('name', '分类名称', AttachmentCategory::getNameById($id))->col(18); - $form[] = Elm::hidden('type', 'images')->col(18); + $form[] = Elm::hidden('type', $this->type)->col(18); $form = Form::make_post_form($form, Url('saveCategory', ['id' => $id])->build()); $this->assign(compact('form')); return $this->fetch("public/form-builder"); @@ -100,7 +100,7 @@ class Images extends AuthController { $data = Util::postMore([ ['pid', 0], - ['type', 'images'], + ['type', $this->type], ['name', ''] ]); if ($data['name'] == '') return app("json")->fail("分类名称不能为空"); @@ -155,7 +155,7 @@ class Images extends AuthController $image = Attachment::get($id); $form = array(); $form[] = Elm::select('cid', '选中分类', (int)$image['cid'])->options(AttachmentCategory::returnOptions())->col(18); - $form[] = Elm::hidden('type', 'images')->col(18); + $form[] = Elm::hidden('type', $this->type)->col(18); $form = Form::make_post_form($form, Url('saveImage', ['id' => $id])->build()); $this->assign(compact('form')); return $this->fetch("public/form-builder"); @@ -183,7 +183,10 @@ class Images extends AuthController try { switch ($image['storage']) { case 1: - unlink(app()->getRootPath() . 'public' . $image['path']); + $filePath = app()->getRootPath() . 'public' . $image['path']; + if (file_exists($filePath)){ + unlink(app()->getRootPath() . 'public' . $image['path']); + } break; case 2: QcloudCoService::del(str_replace(system_config("storage_domain"), "", $image['path'])); diff --git a/app/admin/controller/SystemConfig.php b/app/admin/controller/SystemConfig.php index f539980..87f7c8e 100644 --- a/app/admin/controller/SystemConfig.php +++ b/app/admin/controller/SystemConfig.php @@ -43,7 +43,10 @@ class SystemConfig extends AuthController } } } - $tabList = tModel::lst($where['status'] = 1); + $where = [ + 'status' => 1 + ]; + $tabList = tModel::lst($where); $this->assign("tab_id", $tab_id); $this->assign("tab_list", $tabList['data']); $this->assign("system", $system); diff --git a/app/admin/controller/User.php b/app/admin/controller/User.php index fa976f8..61c46ee 100644 --- a/app/admin/controller/User.php +++ b/app/admin/controller/User.php @@ -67,7 +67,7 @@ class User extends AuthController $form = array(); $form[] = Elm::input('username', '登录账号')->col(10); $form[] = Elm::input('nickname', '昵称')->col(10); - $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/images/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)))->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::password('password', '密码')->col(10); $form[] = Elm::input('tel', '电话')->col(10); $form[] = Elm::email('email', '邮箱')->col(10); @@ -91,7 +91,7 @@ class User extends AuthController $form = array(); $form[] = Elm::input('username', '登录账号', $ainfo['username'])->col(10); $form[] = Elm::input('nickname', '昵称', $ainfo['nickname'])->col(10); - $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/images/index', array('fodder' => 'avatar', 'limit' => 1)), $ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10); + $form[] = Elm::frameImage('avatar', '头像', Url::buildUrl('admin/image/index', array('fodder' => 'avatar', 'limit' => 1)), $ainfo['avatar'])->icon("ios-image")->width('96%')->height('440px')->col(10); $form[] = Elm::password('password', '密码', $ainfo['password'])->col(10); $form[] = Elm::input('tel', '电话', $ainfo['tel'])->col(10); $form[] = Elm::email('email', '邮箱', $ainfo['email'])->col(10); diff --git a/app/admin/view/admin/profile.html b/app/admin/view/admin/profile.html index 1ae1855..9e3dbdd 100644 --- a/app/admin/view/admin/profile.html +++ b/app/admin/view/admin/profile.html @@ -389,7 +389,7 @@ $loading; // ajax上传 - $.ajax("/admin/files/baseToImage", { + $.ajax("/admin/file/baseToImage", { type: 'post', data: {"image": base64Data}, dataType: 'json', diff --git a/app/admin/view/article/add.html b/app/admin/view/article/add.html index e76a9af..4be148e 100644 --- a/app/admin/view/article/add.html +++ b/app/admin/view/article/add.html @@ -5,6 +5,8 @@ {include file="public/header" /} + +