![Avatar of SimonUK](https://cdn.experts-exchange.com/images/experts-exchange/avatar-01-large.gif)
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
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](https://cdn.experts-exchange.com/images/experts-exchange/avatar-01-large.gif)
What type of server do you have ... Windows, Unix, MacOS?
![Avatar of KennyTM](https://cdn.experts-exchange.com/images/experts-exchange/avatar-01-large.gif)
Hi.
(For PHP)
Use opendir()... readdir()... etc.
Or simply use glob().
(For PHP)
Use opendir()... readdir()... etc.
Or simply use glob().
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
![Avatar of SimonUK](https://cdn.experts-exchange.com/images/experts-exchange/avatar-01-large.gif)
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
![Avatar of nltech](https://filedb.experts-exchange.com/files/public/2013/11/18/54898811-58fb-4112-9836-1cacadc60af1.png)
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
![Avatar of Mr_Lenehan](https://cdn.experts-exchange.com/images/experts-exchange/avatar-01-large.gif)
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(p reg_replac e('/\..*$/ ', '', $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?
<?php
$imageLocation = "images/myImage.jpg"
$dirpath = "somedirectory";
$dh = opendir($dirpath);
while (false !== ($file = readdir($dh))) {
if (!is_dir("$dirpath/$file")
echo htmlspecialchars(ucfirst(p
}
}
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](https://cdn.experts-exchange.com/images/experts-exchange/avatar-01-large.gif)
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
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