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]
Name | Type | Size | Last Mod. |
---|---|---|---|
",basename($file['name'])," | \n"; echo "{$file['type']} | \n"; echo "{$file['size']} | \n"; echo "",date('r', $file['lastmod'])," | \n"; echo "
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.