View Full Version : Such and such download x amount of times
I'm looking to add a (i hope) small line of code which will show how many times a file has been downloaded.
for example i have on my site the first doom game and after the description i'd like it to say...
downloaded xxx times
xxx being a number obviously.
Is this easily done and if so how?
devinemke
03-02-2005, 08:17 PM
store the number of downloads in a database. instead of linking directly to the file, link to a PHP script that updates the database and then sends a header to the browser with the file content.
Ok, i get what you're saying but i'm no php expert by any means.
Coul ddo with some help on that...
Hawkmoon
03-03-2005, 12:42 AM
Have your <a href> link to a file like this.
-Hawkmoon
//Connect to your database then:
$sql = "UPDATE your_table SET COUNTER=(COUNTER+1) WHERE GAME='Doom'";
if(mysql_query($sql)) {
header("Location: game_folder\doom.zip");
} else {
echo(mysql_error());
}
Right, i know what you're trying to tell me there but how do i incorporate that into a big standard <a href> link?
Do i see the need for a MySQL database? :(
Hawkmoon
03-03-2005, 04:56 PM
<a href='download_doom.php'>Download Doom</a>
Then in download_doom.php:
//Connect to your database then:
$sql = "UPDATE your_table SET COUNTER=(COUNTER+1) WHERE GAME='Doom'";
if(mysql_query($sql)) {
header("Location: game_folder\doom.zip");
} else {
echo(mysql_error());
}
if you REALLY don't want to use a database to track this, then make download_doom.php something like this:
$filename = "counter.php";
$count = file($filename);
$current_count = $count[0];
if($current_count=="") {
$current_count = 1;
} else {
$current_count++;
}
$file = fopen($filename,"w+");
fwrite($file,"$current_count");
header("Location: game_folder\doom.zip");
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.