Multiple Directory Listing

Hello I’m new to this forum!

I am so lost with this issue, the smallest of things could be the answer.

I am creating a portal for a small project that it’s only function is to store important files and for viewers to view and download this files from this portal. All of the files would be located in a secure server.

On my main (index)page, I have links to different topics (Presentations, Contact List, etc.). To each link represents a directory, and to each one I’m trying to display on the page is a list of all the files in the directory, including subdirectories in which when I click on it, it goes to another page of files, and so on and so forth! Now I display it in HTML, but as it displays on the webpage, I want it to be able to go to directory page to subdirectory page without losing the link with each page.

So I have used this code here from http://www.the-art-of-web.com/php/dirlist/

I used this function getfilelist, so when I call it in the directory php page, all I would call is the folder (lets say presentations)

[php]<?PHP
// Original PHP code by Chirp Internet: www.chirp.com.au
// Please acknowledge use of this code by including this header.

function getFileList($dir, $recurse=false)
{
// array to hold return value
$retval = array();

// add trailing slash if missing
if(substr($dir, -1) != "/") $dir .= "/";

// open pointer to directory and read list of files
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading");
while(false !== ($entry = $d->read())) {
  // skip hidden files
  if($entry[0] == ".") continue;
  if(is_dir("$dir$entry")) {
    $retval[] = array(
      "name" => "$dir$entry/",
      "type" => filetype("$dir$entry"),
      "size" => 0,
      "lastmod" => filemtime("$dir$entry")
    );
    if($recurse && is_readable("$dir$entry/")) {
      $retval = array_merge($retval, getFileList("$dir$entry/", true));
    }
  } elseif(is_readable("$dir$entry")) {
    $retval[] = array(
      "name" => "$dir$entry",
      "type" => mime_content_type("$dir$entry"),
      "size" => filesize("$dir$entry"),
      "lastmod" => filemtime("$dir$entry")
    );
  }
}
$d->close();

return $retval;

}
?>[/php]

So the HTML would look like this:

[php]

<?PHP // output file list as table rows foreach($dirlist as $file) { if($file['type'] != 'application/pdf') continue; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; } ?>
Name Type Size Last Mod.
",basename($file['name']),"{$file['type']}{$file['size']}",date('r', $file['lastmod']),"
[/php]

I don’t have my actual code with me, I could come back and post it later, but this is what I’ve used.

Now I am able to display the files in the directory and it also shows the subdirectories, however when I click on them, they go to a separate white page in which shows the contents, but when you go back to the parent directory, it doesn’t go back to the previous page.

What I have done is apply the HTML code to each page, hiding the subdirectories or other php pages, and creating links to the directories so when you go to that link, it’ll display all files in that subdirectory.

I’m trying to reduce work on this end, as I upload more and more files I want to show them updated simultaneously. Please help, and appreciate your help in advance.

Sorry about that, I wasn’t sure if the thread when through,

[php]

<?PHP include("getFileList.php") ?> Action Items



ATOFs
Action Items

..Home
<?PHP $dirlist = getFileList("Action Items");

// output file list as table rows
foreach($dirlist as $file) {
if($file[‘type’] == ‘dir’) { continue;}
if($file[‘type’] == ‘text/html’) { continue;}
echo “

\n”;
echo “\n";
echo “\n”;
echo “\n”;
echo “\n";
echo “\n”; }

?>

Name Type Size Last Mod.
<a href=”{$file[‘name’]}">",basename($file[‘name’]),"{$file[‘type’]}({$file[‘size’]})”,date(‘r’, $file[‘lastmod’]),"
<tr class="odd">
   <td><a href="/tsprgPortal/Action Items/Action Items Archives.php"> Action Items Archives..</a></td>
</tr>
File Name
  </td>
</tr>

[/php]

This is what I’ve been doing alternatively, for each folder/directory I’ve scan the directory for files and displayed them by name, type, size, and last modified date. Then instead of reading the subdirectory and displaying it, I’ve created a new link to go to a new page and scan that particular directory. So the reason for making this thread is I’m trying to have a directory listing to which will list the directory and files included and able to download those files. Then when I click on the directory, it creates a new page with it’s own list of files. Again I greatly appreciate this for anyone who can help me!

Nobody? I have seen other examples of directory listing online, however none has matched what I’ve been trying to do.

I’ve also checked this example out too

the format of which the directory listing is displayed is what I’m trying to do:
http://www.evoluted.net/stuff/

I believe I may have solved it but I’m not sure if there is another way yet:

in getFileList.php where I define if the entry is directory:

[php]$retval[] = array(
“name” => “$dir$entry/”,[/php]

Changed it to

[php]$retval[] = array(
“name” => “$dir$entry.php”,[/php]

And it worked, all I would have to do is change the table format. I’m still not sure if there is another way however.

Ok, say if for each subdirectory that uploads into the server, I want to create a link to a subdirectory page with its contents.

So if the new subdirectory is uploaded into the server, I want to scan the parent directory of any subdirectories, make a new directory and link of that subdirectory, and list all of its contents.

Now what I’m doing is I want to create that folder or php page automatically so when something new is added, it would apply on that new addition.

Please let me know if it’s confusing as to how I’m explaining it?? Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service