Jump to content

PHP file list


digitalrjs

Recommended Posts

I want to display a list of documents or files for example pdfs from a set of files and open them up.

 

<?php

echo "";

//The path to the style directory
$dirpath = "pdf/";
$dl = opendir($dirpath);
while (false !== ($file = readdir($dl))) {

//admit sub directories
if (!is_dir("$dirpath/$file")) {

echo "$file";
}
}
closedir($dl);
//Close Select

?>


 

one.pdf

two.pdf

three.pdf

 

1. I want to order the files by date

2.  I want to open up the displayed files

 

Link to comment
https://forums.phpfreaks.com/topic/121803-php-file-list/
Share on other sites

$dirpath = "pdf/";
$dl = opendir($dirpath);
while (false !== ($file = readdir($dl))) {
    
    //admit sub directories
    if (!is_dir("$dirpath/$file")) {
        $mod = filemtime("$dirpath/$file");
        $files[$file] = $mod;                      // store in array
    }
}
closedir($dl);
//Close Select

asort($files);                                     // sort array by date

foreach ($files as $fn => $mod)
{
    $dt = date ('d M y H:i:s', $mod);
    echo "<a href='$dirpath/$fn'>$fn</a> ($dt) <br />";
}

Link to comment
https://forums.phpfreaks.com/topic/121803-php-file-list/#findComment-629652
Share on other sites

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.