Index page displaying folder content

Spacemail by SpaceshipSpacemail by Spaceship
Watch

hitman

Established Member
Impact
0
Is there a way to create an index page (with customisable layout) that automaticaly lists the files contained in the same folder with a hyperlink so that people can download the file directly? The index page will update itself everytime a file is copied into the folder.
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
There is a way to do it in php, insert this code into where you want the links to be:

PHP:
$dir = "path/to/directory";
$dh = opendir($dir);

while (false !== ($file = readdir($dh)))
 {
   if (!is_dir("$dir/$file"))
    {
      echo "<a href=\"$dir/$file\">$file</a><br />\n";
    }
 }

That will ouput something like this:

file1.exe
file2.zip
file3.jpg

With hyperlinks to the files.
 
0
•••
Thanks! I've uploaded an index file with only this in it:
PHP:
<?php
$dir = ""; 
$dh = opendir($dir); 

while (false !== ($file = readdir($dh))) 
{ 
if (!is_dir("$dir/$file")) 
{ 
echo "<a href=\"$dir/$file\">$file</a><br />\n"; 
} 
} 
?>

But when i load the page it gives me this:

Warning: readdir(): supplied argument is not a valid Directory resource in /home/.server/username/domain.com/series/uploads/index.php on line 5
 
0
•••
Try changing $dir to "./"
 
0
•••
Mikor said:
Try changing $dir to "./"
I think it needs a full path, rather than a relative path.

So maybe try changing dir to this if that doesn't work.

$dir = "/home/.server/username/domain.com/series/uploads/";

Rhett.
 
0
•••
I just tested the script and ./ works. Of course the full path would work, too.

I use a modified version of this to show what's in a directory. (demo)
 
0
•••
Dynadot — .com TransferDynadot — .com Transfer
CatchedCatched

We're social

Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
DomDB
NameFit
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back