diff --git a/.gitignore b/.gitignore index 0bf2f201..64a8884d 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 82ced9c2..daa036ec 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 0ccfe789..b9ebaf54 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 839fdcc3..8e99d6ae 100644 --- a/application/admin/view/common/header.html +++ b/application/admin/view/common/header.html @@ -42,6 +42,12 @@ +