diff --git a/.gitignore b/.gitignore index 0bf2f201492379d2dca5047d24006ecc49d1940e..64a8884d318fa1343541cbd0a2713a51dcd667f1 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/application/admin/command/Install/fastadmin.sql b/application/admin/command/Install/fastadmin.sql index 82ced9c23d8def8f72cf13ddb542ae21885587eb..daa036ec2b3374e6dfdd7be52544ae6f9448d318 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 0ccfe7893971852d17a9b7daab80da236b8eb4b1..b9ebaf5476a27e81dd72928f6a9a222041ba0bd8 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异步请求接口 @@ -183,6 +184,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 +241,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; @@ -328,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 839fdcc3c17cb21ab9846f234cbea578a16ca107..8e99d6ae98b6845dea16ca7242a7169b28494e78 100644 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -42,6 +42,12 @@ +