How do you auto delete all files under a sub directory after x-time (let say after 24 hours) - without using a cronjob command from server or pl. How can you do this just us
Here is another example that uses GLOB and it will delete any file
$files = glob('path/to/your/files/*');
foreach($files as $file) { // iterate files
// if file creation time is more than 5 minutes
if ((time() - filectime($file)) > 3600) { // 86400 = 60*60*24
unlink($file);
}
}
or if you want to exclude certain files
$files = preg_grep('#\.txt#', glob('/path/to/your/files/*'), PREG_GREP_INVERT);