How to delete all files in a folder after a certain time
I am using this code to delete all files in a 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 a certain time, for example, after 6 months, all files in the folder should be deleted. I have searched more, but all codes are related to the file creation date, but not the usual specific time.
+3
source to share
2 answers