定时删除

pull/141/head
icret 2023-02-13 14:18:46 +08:00
parent 77b8636519
commit 446a907fca
3 changed files with 63 additions and 47 deletions

View File

@ -581,7 +581,7 @@ auto_delete(); //定时删除
</form>
</div>
<div class="form-group col-md-3">
<h5 class="header-dividing" data-toggle="tooltip" title="仅限存储分类路径为 Y/m/d/ 格式<br/>且每天需要访问一次后台才生效<br/>超过定时日期前的不删除">定时删除 <small>数值为<code>0</code>时关闭</small></h5>
<h5 class="header-dividing" data-toggle="tooltip" title="仅限存储分类路径为 Y/m/d/ 格式<br/>且每天需要访问一次后台才生效<br/>先重命名要删除文件夹作为备份<br/>超过定时日期的2倍后再彻底删除重命名的文件夹<br/>超过定时日期前和开启分离文件夹不删除">定时删除 <small>数值为<code>0</code>时关闭</small></h5>
<form action="<?php echo $_SERVER['SCRIPT_NAME']; ?>" method="post">
<div class="input-group">
<span class="input-group-addon">天数</span>
@ -677,6 +677,27 @@ auto_delete(); //定时删除
<label style="font-weight: bold">API 上传</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="以上传用户的Token ID创建目录">
<input type="hidden" name="token_path_status" value="0">
<input type="checkbox" name="token_path_status" value="1" <?php if ($config['token_path_status']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">API 分离</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="以登陆账号名称创建上传目录">
<input type="hidden" name="guest_path_status" value="0">
<input type="checkbox" name="guest_path_status" value="1" <?php if ($config['guest_path_status']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">用户分离</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="管理员独立上传目录<br />* 自定义目录暂未提供接口,如需修改请修改config.php中的admin_path">
<input type="hidden" name="admin_path_status" value="0">
<input type="checkbox" name="admin_path_status" value="1" <?php if ($config['admin_path_status']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">管理分离</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="* 如果不懂就关闭<br /> * 1. 图片链接会隐藏<?php echo $config['path']; ?>目录<br />* 2. 网站与图片域名不能相同<br />* 3. 图片域名需绑定到<?php echo $config['path']; ?>目录">
<input type="hidden" name="hide_path" value="0">
@ -691,6 +712,13 @@ auto_delete(); //定时删除
<label style="font-weight: bold">源图保护</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="广场图片以上传时间倒序 | 正序">
<input type="hidden" name="showSort" value="0">
<input type="checkbox" name="showSort" value="1" <?php if ($config['showSort']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">广场排序</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="上传后显示删除链接<br/>删除链接是经过加密的">
<input type="hidden" name="show_user_hash_del" value="0">
@ -705,34 +733,6 @@ auto_delete(); //定时删除
<label style="font-weight: bold">显示统计</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="广场图片以上传时间倒序 | 正序">
<input type="hidden" name="showSort" value="0">
<input type="checkbox" name="showSort" value="1" <?php if ($config['showSort']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">广场排序</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="以登陆账号名称创建上传目录">
<input type="hidden" name="guest_path_status" value="0">
<input type="checkbox" name="guest_path_status" value="1" <?php if ($config['guest_path_status']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">用户分离</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="以Token ID创建目录">
<input type="hidden" name="token_path_status" value="0">
<input type="checkbox" name="token_path_status" value="1" <?php if ($config['token_path_status']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">Token分离</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="管理员独立上传目录<br />* 自定义目录暂未提供接口,如需修改请修改config.php中的admin_path">
<input type="hidden" name="admin_path_status" value="0">
<input type="checkbox" name="admin_path_status" value="1" <?php if ($config['admin_path_status']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">管理分离</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="使用加密链接删除的文件移动至图片回收">
<input type="hidden" name="image_recycl" value="0">
@ -755,13 +755,6 @@ auto_delete(); //定时删除
<label style="font-weight: bold">图床模式</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="检测图床的 PHP扩展 | 安全设置 | 鉴黄 | 版本 | 文件路径">
<input type="hidden" name="checkEnv" value="0">
<input type="checkbox" name="checkEnv" value="1" <?php if ($config['checkEnv']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">环境自检</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="上传日志每月保存一个文件<br/>经测试二十万条数据并不影响速度!">
<input type="hidden" name="upload_logs" value="0">
@ -769,6 +762,13 @@ auto_delete(); //定时删除
<label style="font-weight: bold">上传日志</label>
</div>
</div>
<div class="col-md-2">
<div class="switch switch-inline" data-toggle="tooltip" title="检测图床的 PHP扩展 | 安全设置 | 鉴黄 | 版本 | 文件路径">
<input type="hidden" name="checkEnv" value="0">
<input type="checkbox" name="checkEnv" value="1" <?php if ($config['checkEnv']) echo 'checked="checked"'; ?>>
<label style="font-weight: bold">环境自检</label>
</div>
</div>
</div>
<div class="col-md-12">
<div class="panel">
@ -1286,7 +1286,7 @@ auto_delete(); //定时删除
<input type="text" class="form-control" name="waterImg" required="required" value="<?php echo $config['waterImg']; ?>" onkeyup="this.value=this.value.replace(/\s/g,'')">
</div>
<div class="form-group col-md-6">
<label data-toggle="tooltip" title="水印中含有中文的,请选用符合GB/2312的字体">文字水印字体路径</label>
<label data-toggle="tooltip" title="水印中含有中文的,请选用符合GB/2312的字体">文字水印 | 验证码的字体路径</label>
<input type="text" class="form-control" name="textFont" required="required" value="<?php echo $config['textFont']; ?>" onkeyup="this.value=this.value.replace(/\s/g,'')">
</div>
<div class="form-group col-md-3">
@ -1294,7 +1294,7 @@ auto_delete(); //定时删除
<input type="text" class="form-control" name="waterText" required="required" value="<?php echo $config['waterText']; ?>" onkeyup="this.value=this.value.trim()">
</div>
<div class="form-group col-md-3">
<label data-toggle="tooltip" title="格式RGBA 末尾为透明度0-127 0为不透明,仅支持文字水印">水印颜色</label>
<label data-toggle="tooltip" title="格式RGBA 末尾为透明度0-127 0为不透明,仅支持文字水印">文字水印颜色</label>
<input type="text" name="textColor" class="form-control" value="" readonly data-jscolor="{preset:'myPreset'}">
</div>
<div class="form-group col-md-6">

View File

@ -1722,28 +1722,44 @@ function ip_upload_counts()
/**
* 自动删除
* 开启自动删除后会先重命名文件夹作为备份
* 自动删除日期超过定时的2倍时间后再彻底删除重命名的文件夹
*/
function auto_delete()
{
global $config;
if ($config['auto_delete'] && $config['storage_path'] == 'Y/m/d/') {
$dir = APP_ROOT . $config['path'] . date('Y/m/d/', strtotime(-$config['auto_delete'] . 'day'));
if (is_dir($dir)) {
/** 重命名要删除的文件夹 */
$Odir = APP_ROOT . $config['path'] . date('Y/m/d', strtotime(-$config['auto_delete'] . 'day')); // 重命名文件夹路径
$Rdir = APP_ROOT . $config['path'] . date('Y/m/d', strtotime(-$config['auto_delete'] . 'day')) . '_auto_delete'; // 新命名文件夹路径
if (is_dir($Odir)) { // 执行重命名
rename($Odir, $Rdir);
$log = date('Y-m-d H:i:s') . $Rdir . ' rename succees';
} else {
$log = date('Y-m-d H:i:s') . $Rdir . ' rename failed';
}
/** 定时删除已经重命名的文件夹路径 */
$Ddir = APP_ROOT . $config['path'] . date('Y/m/d', strtotime(-$config['auto_delete'] * 2 . 'day')) . '_auto_delete'; // 文件夹路径
if (is_dir($Ddir)) { // 执行删除
try {
if (deldir($dir)) {
$log = date('Y-m-d H:i:s') . $dir . ' delete succees';
if (deldir($Ddir)) {
$log = date('Y-m-d H:i:s') . $Ddir . ' delete succees';
} else {
throw new Exception(date('Y-m-d H:i:s') . $dir . ' delete failed');
throw new Exception(date('Y-m-d H:i:s') . $Ddir . ' delete failed');
}
} catch (Exception $e) {
$log = $e->getMessage();
}
if (!is_dir(APP_ROOT . '/admin/logs/tasks/')) {
mkdir(APP_ROOT . '/admin/logs/tasks/', 0755, true);
}
file_put_contents(APP_ROOT . '/admin/logs/tasks/auto_delete.php', $log . PHP_EOL, FILE_APPEND | LOCK_EX);
}
// 写入日志
file_put_contents(APP_ROOT . '/admin/logs/tasks/auto_delete.php', $log . PHP_EOL, FILE_APPEND | LOCK_EX);
return true;
}
return false;
}

View File

@ -115,7 +115,7 @@ $config=Array
'guest_path_status'=>0,
'token_path_status'=>0,
'admin_path'=>'u',
'update'=>'2023-02-12 20:44:03',
'update'=>'2023-02-13 12:54:50',
'footer'=>'<a href="https://github.com/icret/EasyImages2.0" target="_blank" rel="nofollow" data-toggle="tooltip" title="Since 2018 - Github">© Since 2018</a>
<a href="https://png.cm/" target="_blank" data-toggle="tooltip" title="EasyImage 简单图床">EasyImage</a>
<a href="/admin/terms.php" target="_blank" data-toggle="tooltip" title="使用协议">DMCA</a>