From 716bb2e2c544bb2272320b59acbfc6f13b7a00d1 Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Fri, 5 May 2017 15:12:27 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=85=BC=E5=AE=B9windows=E4=B8=8Bapache?= =?UTF-8?q?=E7=9A=84pathinfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 +++- public/.htaccess | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 0bf2f2014..64a8884d3 100755 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ composer.lock thinkphp vendor runtime -public/assets/libs/ \ No newline at end of file +public/assets/libs/ +/application/admin/command/Install/*.lock +/public/uploads diff --git a/public/.htaccess b/public/.htaccess index 0ac53ff79..864872e57 100755 --- a/public/.htaccess +++ b/public/.htaccess @@ -4,5 +4,5 @@ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] + RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1] -- Gitee From e10619221f8397d79ab2177b25f69b304a76ac58 Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Fri, 5 May 2017 15:35:59 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=EF=BC=9B=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E5=AD=98=E5=9C=A8=E9=99=84=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=B7=B2=E5=AD=98=E5=9C=A8=E5=88=99=E4=B8=8D=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/command/Install/fastadmin.sql | 4 +++- application/admin/controller/Ajax.php | 13 ++++++++++++- application/extra/upload.php | 10 +++++----- public/assets/js/backend/general/attachment.js | 8 ++++++-- public/assets/js/require-upload.js | 4 ++-- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql index 82ced9c23..daa036ec2 100644 --- a/application/admin/command/Install/fastadmin.sql +++ b/application/admin/command/Install/fastadmin.sql @@ -93,7 +93,9 @@ CREATE TABLE `fa_attachment` ( `createtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建日期', `updatetime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间', `uploadtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '上传时间', - PRIMARY KEY (`id`) + `sha1` varchar(40) NOT NULL DEFAULT '' COMMENT '文件 sha1编码', + PRIMARY KEY (`id`), + UNIQUE KEY `sha1` (`sha1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='附件表'; -- ---------------------------- diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index 0ccfe7893..68f20705c 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -183,6 +183,16 @@ class Ajax extends Backend { $this->code = -1; $file = $this->request->file('file'); + + //判断是否已经存在附件 + $sha1 = $file->hash(); + $uploaded = model("attachment")->where('sha1',$sha1)->find(); + if($uploaded){ + $this->code = 200; + $this->data = $uploaded['url']; + return; + } + $upload = Config::get('upload'); preg_match('/(\d+)(\w+)/', $upload['maxsize'], $matches); @@ -230,7 +240,8 @@ class Ajax extends Backend 'imageframes' => 0, 'mimetype' => $fileInfo['type'], 'url' => $uploadDir . $splInfo->getSaveName(), - 'uploadtime' => time() + 'uploadtime' => time(), + 'sha1' => $sha1, ); model("attachment")->create(array_filter($params)); $this->code = 200; diff --git a/application/extra/upload.php b/application/extra/upload.php index 421b3e3e7..ffcfb4245 100644 --- a/application/extra/upload.php +++ b/application/extra/upload.php @@ -5,19 +5,19 @@ return [ /** * 上传地址,如果不使用又拍云,则可以使用/ajax/upload */ - 'uploadurl' => 'http://v0.api.upyun.com/yourbucketname', + 'uploadurl' => '/admin/ajax/upload', /** * 又拍云或本机的CDN地址 */ - 'cdnurl' => 'http://yourbucketname.b0.upaiyun.com', + 'cdnurl' => '', /** * 上传成功后的通知地址 */ - 'notifyurl' => 'http://www.yoursite.com/upyun/notify', + 'notifyurl' => '', /** * 又拍云Bucket */ - 'bucket' => 'yourbucketname', + 'bucket' => '', /** * 生成的policy有效时间 */ @@ -29,7 +29,7 @@ return [ /** * 文件保存格式 */ - 'savekey' => '/uploads/media/{year}{mon}{day}/{filemd5}{.suffix}', + 'savekey' => '/uploads/{year}{mon}{day}/{filemd5}{.suffix}', /** * 最大可上传大小 */ diff --git a/public/assets/js/backend/general/attachment.js b/public/assets/js/backend/general/attachment.js index 51ec4fa1e..13473a314 100644 --- a/public/assets/js/backend/general/attachment.js +++ b/public/assets/js/backend/general/attachment.js @@ -54,9 +54,13 @@ define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'config'], function ( }, formatter: { thumb: function (value, row, index) { - console.log(row); + //console.log(row); if (row.mimetype.indexOf("image") > -1) { - return ''; + if (Config.upload.bucket.replace(/^\s+|\s+$/gm,'').length === 0){ + return ''; + } else { + return ''; + } } else { return '无'; } diff --git a/public/assets/js/require-upload.js b/public/assets/js/require-upload.js index c5d1826a9..685214565 100755 --- a/public/assets/js/require-upload.js +++ b/public/assets/js/require-upload.js @@ -69,11 +69,11 @@ define(['jquery', 'bootstrap', 'backend', 'config', 'plupload'], function ($, un try { var ret = JSON.parse(info.response); if (ret.hasOwnProperty('code')) { - ret.data = ret.code == 200 ? ret : ret.data; + ret.data = ret.code == 200 ? ret.data : ret.data; ret.code = ret.code == 200 ? 1 : ret.code; var data = ret.hasOwnProperty("data") && ret.data != "" ? ret.data : null; var msg = ret.hasOwnProperty("msg") && ret.msg != "" ? ret.msg : ""; - $("input[data-plupload-id='" + id + "-text']").val(data.url); + $("input[data-plupload-id='" + id + "-text']").val(data); var afterUpload = $("#" + id).data("after-upload"); if (afterUpload && typeof Upload.api.custom[afterUpload] == 'function') { Upload.api.custom[afterUpload].call(info, id, data); -- Gitee From 0b365562cbe9314b862a4f06c9e1301ed023d6c6 Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Fri, 5 May 2017 15:42:02 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=85=E9=99=A4?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Ajax.php | 22 ++++++++++++++++++++++ application/admin/view/common/header.html | 6 ++++++ public/assets/js/backend/index.js | 16 ++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/application/admin/controller/Ajax.php b/application/admin/controller/Ajax.php index 68f20705c..b9ebaf547 100644 --- a/application/admin/controller/Ajax.php +++ b/application/admin/controller/Ajax.php @@ -9,6 +9,7 @@ use fast\Tree; use think\Config; use think\Db; use think\Lang; +use think\Cache; /** * Ajax异步请求接口 @@ -339,4 +340,25 @@ class Ajax extends Backend } } + /** + * 清空系统缓存 + */ + public function wipeCache() + { + $wipe_cache_type = ['TEMP_PATH', 'LOG_PATH', 'CACHE_PATH']; + foreach ($wipe_cache_type as $item) { + if ($item == 'LOG_PATH') { + $dirs = (array) glob(constant($item) . '*'); + foreach ($dirs as $dir) { + array_map('unlink', (array) glob($dir . DIRECTORY_SEPARATOR . '*.*')); + } + array_map('rmdir', $dirs); + } else { + array_map('unlink', (array) glob(constant($item) . DIRECTORY_SEPARATOR . '*.*')); + } + } + Cache::clear(); + $this->success('清空系统缓存成功!'); + } + } diff --git a/application/admin/view/common/header.html b/application/admin/view/common/header.html index 839fdcc3c..8e99d6ae9 100644 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -42,6 +42,12 @@ +
  • + + + +
  • +