Jump to content

[SOLVED] time help needed


spfoonnewb

Recommended Posts

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

 

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
}

            $now = strtotime("now");
            $last = filemtime("$file");
            
            $calculate = ($now-$last);
            
            if ($calculate > x_amount_of_seconds) {
            	remove_directory($file);
            }
            
            echo "$now - $last = $calculate<br /><br />";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.