Link to home
Start Free TrialLog in
Avatar of SimonUK
SimonUK

asked on

Automatic file listing in HTML or similar

Hi everyone

I'd like to generate an HTML page that lists all the files contained within a specific directory on our web server.  The server is running the usual services so it doesn't matter if the solution is written in HTML, Perl, PHP, whatever - as long as it's simple.

So, for example, when a visiter opens the page www.sitename.com/filelist.html, the page contains a list of all the files in www.sitename.com/files

I'd then like to have an image or button next to each item called 'Download' that visitors click to retrieve the appropriate file.

The next step is to provide another page that allows visitors to upload but that solution seems more common, there appear to be a few examples around so I'll try those!  I'll also need to add security at some point, so users have to log in before they can upload or download - but that can wait.

Thanks


Simon
Avatar of walkerke
walkerke

What type of server do you have ... Windows, Unix, MacOS?
Hi.

(For PHP)

Use opendir()... readdir()... etc.
Or simply use glob().
SOLUTION
Avatar of nltech
nltech

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SimonUK

ASKER

Thanks so far.

It's a Linux server - a fairly standard hosting package.

Great suggestion on the software packages, but they're all fairly extensive and do more than I'm going to use.  What I'm looking for is a page of HTML or PHP that will generate a list of files that exist in a given location, that people can then download - it would be possible to create the 'add file' part and the security later - it's just a proof-of-concept at this stage.

By the way, I'm not familiar with the PHP language, KennyTM - so I'll need some code to get started with !

Thanks


Simon
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i was thinking ahead to where you'll have these file transfers behind a user login. you'll need something more robust than a simple download or upload script, and that's where any of those three scripts will come in to play.  and if you aren't a coder, you'll be best off with a ready-made script. sure it might take a little while to get set up (i use two of them on my own servers, they really aren't too bad to install), but your time invested in them will not be wasted.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, to make the files downloadable with a little image you could do:
<?php
$imageLocation = "images/myImage.jpg"
$dirpath = "somedirectory";
    $dh = opendir($dirpath);
       while (false !== ($file = readdir($dh))) {
          if (!is_dir("$dirpath/$file")) {
               echo htmlspecialchars(ucfirst(preg_replace('/\..*$/', '', $file))) . "<a href='$dirpath/$file'><img src='". $imageLocation."'></a><br>";
          }
       }
closedir($dh);
?>

This would produce output like: somefile [IMAGE] where you could click on the image to download the file.  Does that look like what you are looking for?
Avatar of SimonUK

ASKER

Thanks everyone.

I hope I've divided the points fairly.  Mr Lenehan came up with the specific answer I wanted but KennyTM also provided code that might be helpful to others, and nltech's links were VERY handy and I'm testing one of the products now.


Simon