Hello,

I'm a not a programmer at all and when I tried to build a LibraryBox for my school I didn't know it was a discontinued project.
So I'm here with my MR3020 version 3 (the one that is not supported anymore by the project...) and I managed with my poor little knowledge to implement OpenWRT, PHP, and a nice html page to share files to the students.
I picked up some pieces of PHP code for a nice file explorer (https://github.com/halgatewood/file-directory-list/) which is really nice and comfy, but I would like to put on the index.php page a piece of PHP code in order show the "X" last modified files.
Those files are put in a "Shared" directory with several subdirectories like "Video", "Documents", etc.

I found 2 interesting codes.

The first one gives me all my subdirectories and lists all the files in each :

<?php
error_reporting(E_ALL);
ini_set("display_errors", 0);

function getDirrecurse($path = 'Shared/', $level = 0)
{
    $ignore = array('.', '..');
    $dir = @opendir($path);
        while(false !== ($file = readdir($dir)))
        { 
            if(!in_array($file, $ignore))
            {     
                $spaces = str_repeat('&nbsp;', ($level*4));  
                if(is_dir("$path/$file"))
                { 
                    echo "<strong>$spaces $file</strong><br />"; 
                    getDirrecurse( "$path/$file", ($level+1));       
                } 
                else 
                { 
                    echo "$spaces $file<br />"; 
                }
            }
        }
    closedir($dir); 
}

getDirrecurse();   ?>

The second one gives me the "3" last modified items in a folder but it won't go looking inside the subfolders :

<?php
$dossier = 'Shared/';
$dir = opendir($dossier);

//how many files to display :
$n = 3;

while ($object = readdir($dir))
   {
   if ($object != "." && $object != "..") {

   $filename = $dossier . $object;
   $file_object = array(
         'time' => filemtime($filename),
         'name' => $object,
         'size' => filesize($filename)
                                        );
                    $dir_objects[] = $file_object;
                }
   }

array_multisort($dir_objects, SORT_DESC);
array_splice($dir_objects,$n);

for($i=0;$i<count($dir_objects);$i++)
      {
      echo $dir_objects[$i]['name'].' ('.strftime("%d/%m/%Y à %T", $dir_objects[$i]['time']).')<br/> //shows the name of the files, modification date and time
';
      } 
 ?>

Ideally, I would like to get a link (href) to the "X" last modified files listed with the subfolder like in the first code.
At least getting the second code to dive recursively in each subdirectory instead of just returning the subfolders inside Shared/ ?

Can somebody help me ?

Re: How to display the ... new files within subdirectories in PHP 80 80

Sorry, I'm a bit confused by the question you're asking. Why not use that file-directory-list available at Github you linked to?

What do you mean by a link to [...] like in the first code? The first code block you provided has no links?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.