NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Index page displaying folder content

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-25-2006, 12:06 PM THREAD STARTER               #1 (permalink)
NamePros Member
Join Date: Feb 2005
Posts: 82
hitman is an unknown quantity at this point
 



Index page displaying folder content


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 by hitman; 10-25-2006 at 12:15 PM.
hitman is offline  
Old 10-25-2006, 02:24 PM   #2 (permalink)
NamePros Member
Join Date: Mar 2006
Location: USA - RI
Posts: 49
Horranus is an unknown quantity at this point
 



There is a way to do it in php, insert this code into where you want the links to be:

PHP Code:

$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";
????: NamePros.com http://www.namepros.com/programming/250791-index-page-displaying-folder-content.html
    }
 } 
That will ouput something like this:

file1.exe
file2.zip
file3.jpg

With hyperlinks to the files.
Horranus is offline  
Old 10-25-2006, 02:49 PM THREAD STARTER               #3 (permalink)
NamePros Member
Join Date: Feb 2005
Posts: 82
hitman is an unknown quantity at this point
 



Thanks! I've uploaded an index file with only this in it:
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=250791
$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:

Quote:
Warning: readdir(): supplied argument is not a valid Directory resource in /home/.server/username/domain.com/series/uploads/index.php on line 5
hitman is offline  
Old 10-25-2006, 03:11 PM   #4 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Try changing $dir to "./"
Barrucadu is offline  
Old 10-25-2006, 07:32 PM   #5 (permalink)
 
BillyConnite's Avatar
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,456
BillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond reputeBillyConnite has a reputation beyond repute
 


Wildlife Parkinson's Disease Parkinson's Disease
Originally Posted by Mikor
Try changing $dir to "./"
I think it needs a full path, rather than a relative path.
????: NamePros.com http://www.namepros.com/showthread.php?t=250791

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

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

Rhett.
BillyConnite is offline  
Old 10-25-2006, 08:22 PM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,796
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
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)
Dan is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 09:04 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger