You're here: Home / PHP /

Simple File Server and Downloader Script

If your blogs or sites have download links to your files, you might want to put all of your files in one directory rather than have them scattered throughout your site. This way you can manage them easier.

To download these files, you provide a downloader script. The script can be used for protection from direct download, check user's authentication, write logs, and such.

I've made a simple script for this purpose. It has features:

  • Can download any files: zip, images, pdf, php, etc.
  • Displays a 'You are downloading...' page before sending the file.
  • Simple and easy to develop.

Keywords: simple file server, downloader script, force download, download management

Share:  del.icio.us logo Save to del.icio.us  digg logo Digg this!

comment.gifComments

Hi Nashruddin,

In download.php file, i realise that download.php must be place in the same directory of the folder.Is it possible that i can place it public_html/download.php ,while my download folder is at public_html/upload/? dirname(__FILE__);

Hello Dennis,
Yes it is possible to place download.php in some other directory. Suppose your files reside in /var/www/pub/downloads, just change the line:

$fileserver_path = dirname(__FILE__);

with this:

$fileserver_path = "/var/www/pub/downloads";

Hi!
Is it possible to have the files on a remote server, rather on the local server, if not do you know of a script that can do this.
thx
Petter

This script and your files should be in the same domain. otherwise the script wont work. Sorry I dont have info for such a script.

mas kalo script model situs spt ini http://www.whereweget.com/ itu dimana yah dapetinnya?
mohon info.
thx before

sori aku ga tau downloadnya dimana. tapi aku juga rencana bikin skrip kayak gitu kok. tungguin ya.

everything is working great, however the direct link to the file is not putting the directory in which the file resides.
so the absolute path is domain.com/assets/file.zip
however the link just links to domain.com/file.zip

how do i correct this?

You mean:
1. you put the downloader script at http://www.yourdomain.com/download.php
2. your files reside in http://www.yourdomain.com/assets

if that is the case, change the variable $fileserver_path to the absolute path where your files reside. ex:

$fileserver_path = '/var/www/assets';

Did that, the auto refresh works just fine, its the html link that is not working. The html link is showing http://dl.domain.com/filename.zip which throws me a file not found error but it should read http://dl.domain.com/assets/filename.zip.

Oh I see. It seems like there's a bug in my script. Modify the following line:

"...If it doesn't start, follow this <a href="<?=$req_file?>">link</a>"

to this:

"...If it doesn't start, follow this <a href="assets/<?=$req_file?>">link</a>"

This should solve your problem.

sweet. thx, that did it.

comment.gifAdd your comment

(required, will not be published) (optional)