View Full Version : Number of downloads script?

12-16-2010, 05:03 PM
Hi all,

On my site i'd like to show the number of downloads for prgram 'a', program 'b' etc etc but i'm not sure how to do this.

I'm not looking for anything fancy, but all i know is that it can be done in PHP. Have had a look on HotScripts but can't seem to find anything.

Could anyone point me in the right direction please?.


12-16-2010, 05:07 PM
Just make a php script using header() function for getting the download prompt and at the top/bottom of this script, add the code required to update the DB corresponding to the download actions.

12-16-2010, 05:15 PM
Thanks for the quick reply but very, VERY new to PHP here...a little elaboation on your post by any chance?.

12-16-2010, 05:36 PM
Have a look at Example #1 at http://php.net

Basically, you need to have a script like this in a page, say download.php and then link all your files to be downloaded to this script, say

<a href="download.php?file=file1.txt">file1.txt</a>

<a href="download.php?file=file2.txt">file2.txt</a>
So, you need to make your download.php a little dynamic to accept the file name from $_GET['file'] and insert into the script.

In that same file, add the code to insert/update into DB to update the counter along with the name of the file.

PS: You need to validate the file name first to prevent people from downloading your "secure" files.

12-16-2010, 06:43 PM
A simple search on google would have turned up plenty options for what you need.