[英]How to delete all files in folder after specific time
I am using this code to delete all files in folder 我正在使用此代码删除文件夹中的所有文件
$dir = $_SERVER['DOCUMENT_ROOT'].'/upload/';
$op_dir=opendir($dir);
$x = 5;
$current_time = time();
$difference = $current_time - $x;
while($file=readdir($op_dir ))
{
if($file != "." && $file != ".." ){
var_dump($dir.$file);
unlink ($dir.$file);
}
}
closedir($dir);
But I need to do this action after specific time for example after 6 month all files in the folder should be deleted.I searched more but all codes are related to file creation date not generally specific time. 但是我需要在特定时间之后执行此操作,例如在6个月之后应该删除文件夹中的所有文件。我搜索了更多但是所有代码都与文件创建日期相关,而不是一般特定时间。
如何计算6个月的开始时间,以便我们可以将目录创建时间或节省特定时间保存在数据库中进行计算。最佳选择是cronjob用于此任务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.