Home  »     »     »     »     »  Php script for Listing files based on last modified time

Php script for Listing files based on last modified time

Friday, May 18, 2012


Php script for Listing files based on last modified time

Here is the php script to list the files in a folder based on the modified date

Using the below script you can list files from older to latest or latest to oldest

<?php

// list from a given folder
$folder="test/";
$files = glob( $folder."*.*" ); // to avoid hidden files

// Sort files by modified time, latest to oldest

array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_DESC,$files);

// Use SORT_ASC in place of SORT_DESC for oldest to latest
//array_multisort(array_map( 'filemtime', $files ),SORT_NUMERIC,SORT_ASC,$files);

// display the file names
if(count($files)){

for( $i=0 ; $i < count($files) ; $i++ ){

echo(basename($files[$i])."   <a href='".$folder.$files[$i]."'>Link to the file</a><br>");

}

}

?>



How to link to this page?
If you wish to link to this page from your website, simply Copy and paste the above HTML code to your web page. It will appear on your page as:
Php script for Listing files based on last modified time.




Share this!




comments powered by Disqus

This Weeks 7 Popular Posts


Subscribe to Recent Posts by Email
Stay connected to CROZOOM with regular Email notices of new Techie articles and IT Jobs. Updates will be delivered to your Inbox as soon as they are posted online.

Enter Your Email Address:  

Delivered by FeedBurner   RSS Feed

Search this Blog   



Urgent Openings for PHP trainees, Andriod / IOS developers and PHP developers in Kochi Trivandrum Calicut and Bangalore. Please Send Your updated resumes to recruit.vo@gmail.com   Read more »