spfoonnewb Posted March 10, 2007 Share Posted March 10, 2007 I am trying to make this script that will get the last modified date of all the files in a certain directory. If the time that between the last modified and the current time is greater than x amount of minutes, I want it to run the removedir function, that I will setup once I get it working. I am having trouble getting PHP to subtract the times... Any help is appreciated. <?php function remove_directory($file) { //Delete files, and then rmdir } $dir = "."; if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if( $file != "." && $file != ".." ) { $last_modified = filemtime("$file"); $last = strtotime($last_modified); $now = strtotime("now"); $do3 = ($last-$now); echo "$do3<br /><br />"; } } closedir($dh); } } ?> Link to comment https://forums.phpfreaks.com/topic/42120-solved-time-help-needed/ Share on other sites More sharing options...
Orio Posted March 10, 2007 Share Posted March 10, 2007 This line is not needed, since filemtime() returns a timestamp: $last = strtotime($last_modified); Also, instead of: $do3 = ($last-$now); You should do: $do3 = ($now-$last); (Because $now is bigger than $last) Orio. Link to comment https://forums.phpfreaks.com/topic/42120-solved-time-help-needed/#findComment-204289 Share on other sites More sharing options...
legohead6 Posted March 10, 2007 Share Posted March 10, 2007 something like this maybe.. i dunno ive never tested or done a script like this, the only thing i know works is the minusing hours( the $time variable) $hours=-10 //10 hours ago $time=date("U", strtotime($row[3]))+($hours*3600); //makes the 10 hour ago date based off a timestamp($row[3]) $time2 = date() //cuurent time if($time2 > $time+($hours*3600)){ //do whatever to old files }else{ //do something else } Link to comment https://forums.phpfreaks.com/topic/42120-solved-time-help-needed/#findComment-204293 Share on other sites More sharing options...
spfoonnewb Posted March 10, 2007 Author Share Posted March 10, 2007 $now = strtotime("now"); $last = filemtime("$file"); $calculate = ($now-$last); if ($calculate > x_amount_of_seconds) { remove_directory($file); } echo "$now - $last = $calculate<br /><br />"; Link to comment https://forums.phpfreaks.com/topic/42120-solved-time-help-needed/#findComment-204295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.