Sometimes bloggers/webmasters wants to share something with their user using download and therefore they put the link of the resource in their website so that users/visitors can download the resource. Mostly they point the link to the resource itself and therefore web browser tries to open it in itself.

Here is the example of above explanation: Bitnol.

When you click on the link it will open the image in the browser. So, now user has to save it using save option or ‘CTRL + S’ in Windows OS.

But this is not the correct way for providing your user to download any file. Yes it is good for viewing images in the browser but still user has to save it.

Now the solution is below small PHP script which will handle all your downloads:

Copy and save the above PHP script as ‘download.php’ (whatever name you want) and put it in your server. Now to download any file call it as follows:

http://YOURDOMAIN/download.php?file=PATH

where YOURDOMAIN  = your actual domain name.

and PATH = path to the file to download

Now your download system is ready. You can add more security using session ids like creating a session token for each download so that no one can steal your bandwidth.

 

HomeCodingHow-to GuideFile download script for websites