There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen blue screen of death boot bsod computer connection crash css dell display driver drivers email error explorer firefox firefox 3 hard drive internet internet explorer itunes laptop lcd malware monitor network networking outlook outlook 2003 outlook express printer problem problems ram router security slow software sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
Download links for a folder full of files? - Beginner


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
elute96's Avatar
Senior Member with 106 posts.
 
Join Date: Oct 2005
Location: UK - Wales
Experience: Intermediate
16-Jun-2008, 12:51 PM #1
Download links for a folder full of files? - Beginner
I have folders full of files and id like download links to each file in the folder so is there a way to automatically generate download links for every file in the folder?
Thanks
TheRobatron's Avatar
Computer Specs
Senior Member with 480 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
16-Jun-2008, 02:52 PM #2
Some webhosts will automatically generate index pages for folders that don't already have index pages. You should be able to change the options for this in your web hosting settings.

Alternatively, if you can't do that, you can create a PHP script to do it:
PHP Code:
<?php
$dir 
"./"//Current directory
$files scandir($dir);
foreach (
$files as $f) {
echo 
"\n<a href='$f'>$f</a><br />";
}
?>
elute96's Avatar
Senior Member with 106 posts.
 
Join Date: Oct 2005
Location: UK - Wales
Experience: Intermediate
16-Jun-2008, 05:33 PM #3
Do I just paste the code into website like any code?
Thanks
TheRobatron's Avatar
Computer Specs
Senior Member with 480 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
16-Jun-2008, 05:41 PM #4
Yeah, but remember to give it a .php extension (the logical file name would be index.php, because it is an index page after all). Make sure your webhost supports PHP as well.
elute96's Avatar
Senior Member with 106 posts.
 
Join Date: Oct 2005
Location: UK - Wales
Experience: Intermediate
16-Jun-2008, 05:48 PM #5
ok so i create my page how i want it, add that code and give it a php extension?
TheRobatron's Avatar
Computer Specs
Senior Member with 480 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
17-Jun-2008, 01:17 PM #6
Yep, just paste in the code where you want the list of files to be and call it index.php
wipem's Avatar
Junior Member with 1 posts.
 
Join Date: Jun 2008
Experience: Intermediate
19-Jun-2008, 05:13 AM #7
I want to know how create websites using PHP.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
19-Jun-2008, 07:05 AM #8
Quote:
Originally Posted by TheRobatron View Post
Some webhosts will automatically generate index pages for folders that don't already have index pages. You should be able to change the options for this in your web hosting settings.

Alternatively, if you can't do that, you can create a PHP script to do it:
PHP Code:
<?php
$dir 
"./"//Current directory
$files scandir($dir);
foreach (
$files as $f) {
echo 
"\n<a href='$f'>$f</a><br />";
}
?>
The scandir function required PHP 5, make sure thats the php version your host is running.
TheRobatron's Avatar
Computer Specs
Senior Member with 480 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
19-Jun-2008, 12:12 PM #9
Quote:
Originally Posted by MMJ View Post
The scandir function required PHP 5, make sure thats the php version your host is running.
Don't worry if it isn't - one of my webhosts runs PHP 4, so I use this function instead:
PHP Code:
// Scandir for PHP4
//
if(!function_exists('scandir'))
{
    function 
scandir($dir$sortorder 0)
    {
        if(
is_dir($dir))
        {
            
$dirlist opendir($dir);
           
            while( (
$file readdir($dirlist)) !== false)
            {
                if(!
is_dir($file))
                {
                    
$files[] = $file;
                }
            }
           
            (
$sortorder == 0) ? asort($files) : arsort($files);
           
            return 
$files;
        }
        else
        {
        return 
FALSE;
        break;
        }
    }

Quote:
Originally Posted by wipem View Post
I want to know how create websites using PHP.
You'll need to do quite a bit of reading and learning - look around the internet for tutorials and in your library or book shop for books. I found PHP & MySQL for Dummies very useful, as well as PHP, MySQL and Apache All In One.
__________________
There's no place like 127.0.0.1


Last edited by TheRobatron : 19-Jun-2008 12:27 PM.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
19-Jun-2008, 01:00 PM #10
Nice one.

However the scandir function does return directories.

Last edited by MMJ : 19-Jun-2008 01:09 PM.
TheRobatron's Avatar
Computer Specs
Senior Member with 480 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
19-Jun-2008, 02:48 PM #11
I think (though I've never tried it) that if the if (!is_dir($file)) statement is removed, it will return directories as well:
PHP Code:
// Scandir for PHP4
//
if(!function_exists('scandir'))
{
    function 
scandir($dir$sortorder 0)
    {
        if(
is_dir($dir))
        {
            
$dirlist opendir($dir);
           
            while( (
$file readdir($dirlist)) !== false)
            {
                
                    
$files[] = $file;
                
            }
           
            (
$sortorder == 0) ? asort($files) : arsort($files);
           
            return 
$files;
        }
        else
        {
        return 
FALSE;
        break;
        }
    }

Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 12:56 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.