How to Get the most recent file date using PHP

Post Reply
Tony
Lieutenant
Lieutenant
Posts: 86
Joined: Tue Jul 21, 2009 4:11 pm

How to Get the most recent file date using PHP

Post by Tony » Sun Nov 29, 2009 4:56 am

When you need that most recent update date. You can use this script to get the most recent file date in a given directory. To use current directory, use "./" as the directory name.

Code: Select all

<?PHP 
$path = "./";  // put the directory path here 
foreach (glob($path) as $filename) if (filemtime($filename) >= $recentDate) $recentDate = filemtime($filename);  
$recentDate = date(" F d, Y",$recentDate);   
echo $recentDate; 
?>
Post Reply

Return to “PHP & MySQL”