File Download Script


This file downloading script will allow you to set up a download area on your website which links to files that don’t exist physically on the site. Rather, the files to be downloaded can exist in an alternate location on the file system. It is actually the script in use right on this page for downloading these files.

Need something custom built?
Let me help you get your project back on track. More information here.

Requirements: PHP

These scripts are offered free of charge but with no warranty either stated or implied. Use at your own risk.

Download the script Get a quote for custom work Tip the developer

Filed in: PHP Scripts

29 Responses to “File Download Script”

  1. Rick McCoy Says:

    I’m trying out your dl.php script but having problems. Will not find file. I’ve hard-coded the location to be sure. Simply tells me the file doesn’t exist. Any suggestions?

  2. Zain Says:

    I am having the exact same issue as Rick. It cannot find the file to be downloaded. The scrit is in the site root in a folder of its own, the files are in a seperate folder in the root as well (for purposes of testing the script), so the path should be:

    $download_path = “$DOCUMENT_ROOT/folder_containing_files”;

    The files in the secure folder are such as:

    What are we doing wrong here? Please help.


  3. Admin Says:

    Hey guys,

    Thanks for trying the product. I suspect that the problem you are encountering may be related to how some PHP installs handle global variables. I’ve modified the code in the download slightly to account for this. You can also modify your own installations to use the following download path:
    $download_path = $_SERVER[‘DOCUMENT_ROOT’] . “/folder_containing_files”;

    Thanks for letting me know about the problem.

  4. tim Says:

    Hey James,
    Can the download path be set to a URL? I don’t want to use a path because of securty issues and some of the files will be on a different server that where the script is installed. Thanks

  5. Karim Says:

    Thanks for the script, just wish I could get it to work. All I ever get is “I’m sorry, the file doesn’t seem to exist.”

    Has anyone gotten this script to work?

  6. Steve Says:

    sorry guys… I downloaded it. installed it and it worked fine first time.

    Thanks for the script!

  7. Karim Says:

    Perhaps it’s the PHP install?

    Server Type FreeBSD
    Web Server Apache v1.3.37 (cgi)
    PHP 4.4.4

  8. Stuart Elliot Says:

    i have a collection of titles all go from 1 to 54

    eg old download path


    dl.php?filename=1.rar | 2.rar | 3.rar

    is there anyway of randomizing the download link or somat like that.

  9. Philippe Says:

    Hi James! Your script rocks!! works perfectly for me…

    Thanks a lot!!

  10. Richard Says: doesn’t work

  11. Admin Says:

    Hi Richard,

    Thanks for pointing it out. We just upgraded to a new server and the download script was broken. It has now been fixed.

  12. Matt Says:

    This small change allows for spaces in your file names.

    header(‘Content-Disposition: attachment;filename=”‘.$filename.'”‘);

  13. collector Says:

    Nice script, not overloaded with useless features. But…
    You should escape filename in the script. Currently script opens whole site for hacker attack.
    You could also add hotlinking protection, like it is done in the following script

    This would make your script even more powerful.

  14. petter Says:

    Can’t see how this script would work with files on a remote server?

  15. stephanie Says:

    The filename when called from browser is case-sensitive.
    so dl.php?filename=btn.JPG is totally different than

    In case any newbies can’t get this script to work it is worth pointing out.

  16. rodan Says:

    Thanks for the script. I appreciate a tightly coded example that does the job nicely.

  17. asghar Says:

    It works for me great too,
    but i have a problem why it doesnt support files with space in the name?
    can any one plz help me?

  18. leon Says:

    this is to say thank u to u implementer of this script!
    thank u again ! i’ve tried it and succeed today,but this is not to mean that this was my first trial i’ve been trying for 3 months but 2day i’m very lucky to meet u guy.

    thank u!

  19. Luka Says:

    I was wondering, does this script have any problems when user is downloading large files, like 4-5GB. Most scripts I’ve tried so far broke before 2GB.. so I’d really like to know if you’ve tried that. I’ve got a site where I’m hosting large videos (about the size of single layer DVD), and I’m looking for a solution. So far I had zero luck

  20. rifanoz Says:

    Thanks U
    Tested and work.
    Great script.

  21. Charles Revec Says:

    Yes the script does well. Am directly using it from Tanzania, it is real working good.

  22. Probhat Says:

    Thanks a lot…I was facing lot of problems with my project…your codes rocks…!! great…

  23. spearhead Says:

    Thanks for the script.
    All works well except the mp3 file downloaded is 0 byte and un-playable.

    What went wrong???

  24. Mac Sullivan Says:

    I am very new to PHP and the workings of my webhost, which aren’t so bad separately, but when compounded togeth, it poses and extreme hassle. The document root thing… What location on the server does it refer to? If it’s not the folder the script resides in, any way to set it to that folder?
    Any help is appreciated.

  25. Janean Says:

    It worked! thank you so much! God bless. =)

  26. john Says:

    download link give php error

  27. Admin Says:

    Thanks for bringing this to my attention. The issue has been fixed.

  28. Rakker Says:

    Also can’t see how this would work with a remote server.

    Can’t get separate IP address to work:

  29. Admin Says:

    Hi Rakker,

    This script is not designed for pulling from a remote server. Simply for giving access to files that you do not want to have directly accessible from the website’s filesystem.

    All the best,