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
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
You can use filemtime function to get the last modified date/time and use that to see how old the file is.
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));
}
?>
I'd check out the filemtime() or the filectime() functions. Those will give you the modified and creation times (respectively) of the file.