Daleeburg Posted May 18, 2007 Share Posted May 18, 2007 I am tring to make a script that i will turn into a cron job. Idealily it would check the age of the file and then figure out if it is more then 48 hours old and if it is it will delete it. i have figured out how to check the age and how to delete the files, but how would i find out if they are 48 hours old? ~D Quote Link to comment Share on other sites More sharing options...
per1os Posted May 18, 2007 Share Posted May 18, 2007 <?php $filetime = filemtime($file); $timenow = time(); $timetwodays = time()-3600*48; // two days ago if (($timenow - $filetime) >= $timetwodays) { echo 'The file is older than two days.' }else { echo 'file is not older than two days'; } ?> Un-tested, I would suggest testing it first. Quote Link to comment Share on other sites More sharing options...
Daleeburg Posted May 18, 2007 Author Share Posted May 18, 2007 It almost worked, so here is the working script <?php $filetime = filemtime($file); $timenow = time(); $twodays = 3600*48; // two days ago if (($timenow - $filetime) >= $twodays) { echo 'The file is older than two days.' }else { echo 'file is not older than two days'; } ?> or <?php $filetime = filemtime($file); $timetwodays = time()-3600*48; // two days ago if ($filetime <= $timetwodays) { echo 'The file is older than two days.' }else { echo 'file is not older than two days'; } ?> (second is untested, but should work) Thanks ~D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.