From 980be86c6d4e2e1cca6b79d839ae6e0491c47d69 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 15 Mar 2022 08:56:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E4=B8=B4=E6=97=B6=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E7=9A=84=E8=87=AA=E5=8A=A8=E5=88=A0=E9=99=A4;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/File.php | 24 +++++++++++++++++++++++- app/model/TempImg.php | 14 ++++++++++++++ view/admin/common/_require.html | 19 ++++++++++++++----- 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 app/model/TempImg.php diff --git a/app/admin/controller/File.php b/app/admin/controller/File.php index 1fa1992..e54d335 100644 --- a/app/admin/controller/File.php +++ b/app/admin/controller/File.php @@ -2,6 +2,7 @@ namespace app\admin\controller; +use app\model\TempImg; use app\model\UploadFiles; use app\UploadFiles as AppUploadFiles; use League\Flysystem\Util\MimeType; @@ -103,13 +104,34 @@ class File extends Common file_put_contents($temp_file, $file_data); - // TODO:将文件存入数据库并且删除过期文件 + $model_img = TempImg::create([ + 'path' => $public_file_path + ]); + return json_message([ 'src' => $public_file_path ]); } + public function clearTempImg() + { + $list_img = TempImg::where('create_time', '<', time() - 600)->limit(100)->select(); + + foreach ($list_img as $key => $model_img) { + $temp_file = App::getRootPath() . 'public' . $model_img->path; + + if (file_exists($temp_file)) { + unlink($temp_file); + $model_img->delete(); + } + } + + return json_message([ + 'delete' => $list_img->count() + ]); + } + public function clear($id) { AppUploadFiles::clear($id); diff --git a/app/model/TempImg.php b/app/model/TempImg.php new file mode 100644 index 0000000..3c5f908 --- /dev/null +++ b/app/model/TempImg.php @@ -0,0 +1,14 @@ + { + callClearTempImg() + }, 10000); + }) + } + callClearTempImg()