I'm hoping you guys will give this script a second glance to make sure I'm not screwing anything up... I don't really have a sandbox to test on, so this is a spray-and-pray script for me :-O
The plan is for this to run every 24 hours using a cron job, to delete content uploaded by users in a /cache/ directory. I'm starting to get a tad tight on storage, and these are all obsolete after about an hour, anyway.
$dir = '/home/example/www/cache/';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ((time() - filectime($file)) > 3600) // 60 sec * 60 min = 3600
unlink($file); // or do I need to use unlink($dir . $file)?
}
}
Or is there a better way to do this with bash scripting (which is not my strength) instead of PHP?
If it matters, the first run will probably delete about 100,000 files, and after that it should be less than 100 a day.