tags:

views:

195

answers:

5

Any way to determine file age of an image in a folder using PHP?

I want to delete older files than 2 hours, is this possible without adding timestamp-names to their filenames on upload to the folder?

If so, please give me an example!

thanks

+1  A: 

You can use filemtime function to get the last modified date/time and use that to see how old the file is.

Marek Karbarz
A: 

try with filemtime

Gabriel Sosa
+2  A: 

You are looking for the filmetime function

<?php
// outputs e.g.  somefile.txt was last modified: December 29 2002 22:16:23.

$filename = 'somefile.txt';
if (file_exists($filename)) {
    echo "$filename was last modified: " . date ("F d Y H:i:s.", filemtime($filename));
}
?>
mnml
A: 

You can use date/time of last file modification:

Karol
A: 

I'd check out the filemtime() or the filectime() functions. Those will give you the modified and creation times (respectively) of the file.

Dave DeLong