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 Link to comment https://forums.phpfreaks.com/topic/52017-solved-check-file-age/ 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. Link to comment https://forums.phpfreaks.com/topic/52017-solved-check-file-age/#findComment-256393 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 Link to comment https://forums.phpfreaks.com/topic/52017-solved-check-file-age/#findComment-256415 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.