mirror of
https://gitee.com/ulthon/ulthon_information.git
synced 2026-03-03 16:24:28 +08:00
完成临时图片的自动删除;
This commit is contained in:
@@ -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);
|
||||
|
||||
14
app/model/TempImg.php
Normal file
14
app/model/TempImg.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* @mixin \think\Model
|
||||
*/
|
||||
class TempImg extends Model
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -105,6 +105,15 @@
|
||||
|
||||
|
||||
})
|
||||
|
||||
function callClearTempImg() {
|
||||
$.get('{:url("File/clearTempImg")}', function () {
|
||||
setTimeout(() => {
|
||||
callClearTempImg()
|
||||
}, 10000);
|
||||
})
|
||||
}
|
||||
callClearTempImg()
|
||||
</script>
|
||||
|
||||
<div class="tpl" style="display: none;">
|
||||
|
||||
Reference in New Issue
Block a user