[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 10-25-2006, 11:06 AM   #1 (permalink)
NamePros Member
 
Join Date: Feb 2005
Posts: 82
126.00 NP$ (Donate)

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 11:15 AM.
hitman is offline  
Old 10-25-2006, 01:24 PM   #2 (permalink)
NamePros Member
 
Join Date: Mar 2006
Location: USA - RI
Posts: 49
216.70 NP$ (Donate)

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";
    }
}
That will ouput something like this:

file1.exe
file2.zip
file3.jpg

With hyperlinks to the files.
Horranus is offline  
Old 10-25-2006, 01:49 PM   #3 (permalink)
NamePros Member
 
Join Date: Feb 2005
Posts: 82
126.00 NP$ (Donate)

hitman is an unknown quantity at this point


Thanks! I've uploaded an index file with only this in it:
PHP Code:
<?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:

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, 02:11 PM   #4 (permalink)
Barru.
 
Barrucadu's Avatar
 
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,731
78.50 NP$ (Donate)

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, 06:32 PM   #5 (permalink)
 
BillyConnite's Avatar
 
Join Date: Jul 2005
Location: Coffs H, Australia
Posts: 3,107
47.00 NP$ (Donate)

BillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant futureBillyConnite has a brilliant future

Wildlife Parkinson's Disease Parkinson's Disease
Quote:
Originally Posted by Mikor
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.
__________________
<?php if(1===1){ $computer="fine."; }else{ $computer="broken."; } echo "Your computer is ".$computer; ?>
BillyConnite is offline  
Old 10-25-2006, 07:22 PM   #6 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
 
Join Date: Feb 2006
Posts: 2,801
56.00 NP$ (Donate)

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 07:57 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85