PHP Download List

By Jonesy44 on Aug 16, 2008

Okay well! this page is real helpfull if you want to display a bunch of downloads without needing an sql table, and without having to update the index page

Paste this into a file "index.php" in a NEW directory. something like /downloads or someting then place the link into "opendir" i have no idea if just / will cut it. i use the full path /www/home etc..

Then all you need to do is upload files into the directory! and they will display. the file sizes will also display underneath each file.

For an example of this; go here:

i find this SO usefull to have a simple page which can display what i need w/o having to update it all the time and displaying the size too. hope ya enjoy!

Also, this was my first go with regular expressions in PHP. Hope they work okay! as far as i have tested they work fine. it will display ANY file in the directory EXCLUDING .php files
For a good tutorial i have posted the link in the PHP forums, go check it out here:

if ($handle = opendir('/')) {
  while (false !== ($file = readdir($handle))) {
    if (!preg_match("/\.(.?|php)$/",$file)) {
      echo '<a href="' .$file. '">' .$file. '</a><br>';
      $size = round(filesize($file) / 1024, 2);
      echo '<font style="font-size:11px;">File Size: ' .$size. 'KB;</font><br>';


Sign in to comment.
Jonesy44   -  Nov 30, 2009

Yeaah that probably would make it faster lol. :)

^Neptune   -  Nov 24, 2009

Nice little script. The display kinda reminds me of an XLST'd XML file.

Anyways, take a peek at scandir(), I think it might make the code a little simpler and faster to process:

Hope I helped

Jonesy44   -  Nov 24, 2009

Hi weaver, something isn't "wrong", unless PHP has somehow drastically changed. i'm afraid to say, as much as i like to vent my frustration on code, this is not one of the cases. Check the link, the code still works there :)

Can you confirm that you have changed the directory you are searching through?

sunslayer   -  Nov 23, 2009

@weaver it doesnt actually download the page and try changing your opendir() and filesize() file paths

weaver   -  Nov 23, 2009

It does not work properly for me. I get an error relating to the filesize and when it shows the files I cannot download them by clicking on them So something is wrong.

bnc   -  Aug 15, 2009
$_FILES <?php if ($handle = opendir('files')) { while (false !== ($file = readdir($handle))) { if (!preg_match("/\.(.?|php)$/",$file)) { echo '' .$file. '
'; } } closedir($handle); } ?>
Jonesy44   -  Nov 22, 2008

Well now you're all sorted, Hawkee! Just use my script :L

Hawkee   -  Aug 25, 2008

There have been some rare occasions where I needed to make a HTML document to download a file, but I never took it this far.

Jonesy44   -  Aug 16, 2008

Okay kool, hehe edited. thanks again for the comments. You're just about the only one who does PHP lol!

F*U*R*B*Y*   -  Aug 16, 2008

lol yeah i hate it when you can't think of a name, that really suits it

Jonesy44   -  Aug 16, 2008

Thanks Paul. Much appreciated for the comment. I'll update the name i guess. i wasn't sure what else to call it. lol.

Anyways, it serves its purpose well for my needs. Thanks

F*U*R*B*Y*   -  Aug 16, 2008

Its not exactly a "Download Script" as such, more of a, List of Downloads. A "Download Script" would be, the page loads, clicking on an item, forces it to download (Good ol' Ajax will help)... but never the less, helpful to some young ones....

Rating: 7.5 (Roudning it up to an 8 for the Rating part)

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.