Jump to content

10 Latest modified File name


binoymv

Recommended Posts

Hi friends ,

How to find last latest10 file that are modified.

 

I have a folder named test. In that i am uploading files , i need to take 10 latest file name that are modified.

jhow can i do that . I used filemtime for this one , but in this file modified time is showing but this is not a sorted , how can i sort it by latest modified.

 

Thanks in advance

Binoy

Link to comment
https://forums.phpfreaks.com/topic/128252-10-latest-modified-file-name/
Share on other sites

try something like this

<?php
$files = glob("*.*");
$times = array();
foreach($files as $filename){
    $times[] = array(filemtime($filename),$filename);
}
rsort($times);
foreach($times as $key => $details){
    if($key > 9){
        break;
    }
    echo "{$details[1]} modified at ". date("F d Y H:i:s.", $details[0])."<br>";
}
?>

 

Scott.

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.