Counter<

admin

Administrator
Staff member
I am making a Download page for some mp3s, wallpapers etc ( they are all designed / recorder by myself :P ) and I want a little bit of text underneath each Download saying like
This File Has Been Download ed xxxx Times.

How would I do this?everytime they click on the link you have it in another file that adds to a db or flat file to the name of the file they Download ed. then it gives them the Download box. pretty eassily done. so are they in a db? if not you will need to add them. or you can add it to a flat file with the name of this file the same name as teh file they Download . then add to the number that is already in there. takes more code to do it this way as you have to have that many fopen() functions as you do with files.To expand on scoutt's answer a little more, you could do something like this. But of course you would need the URL stored in a database.

the link for a Download would be like this
Download .php?id=5

and Download .php would GET the id variable, and select the URL from the database where the ID = 5. You then update a Download count column where the id = the gotten id setting it +1 which will be the number of times it's Download ed.

Then you can use the header function and redirect to the file to be Download ed.oh rad, so could anyone tell how to do this? in english? haah I suck with PHP, infact I know nothing about it, i'm trying to learn, soooo... in english? or does anyone have the script we would use to do this? or could someone point me to a place where I could get a script?Yes does anyone have a script or a good tutorial?here ya go
<!-- m --><a class="postlink" href="http://www.alphibia.com/phpscripts.php?p=3">http://www.alphibia.com/phpscripts.php?p=3</a><!-- m --><?php
$conn = mysql_connect("localhost","username","pword");
$db = mysql_select_db("database");

//check if the Download exists first
$requested = $_GET['Download '];
$query = MYSQL_QUERY("SELECT * FROM `TABLENAME` WHERE `Download _name`='$requested' LIMIT 1");
$count = mysql_num_rows($query);
if($count) = 1){
//continue coz the Download is valid.
$Download = MYSQL_FETCH_ARRAY($query);
//update the count
$to_add = $Download ['count'] + 1;
//insert it
$insert = MYSQL_QUERY("UPDATE `wallpaper` SET `count`='$to_add' WHERE `name`='Download _name' LIMIT 1");
//redirect them to the Download
$file = $_GET['Download '];
header("Location: Download s/$file.jpg")
//all done
} else {
print "Invalid Download ";
}
?>

My friend wrote this for me but it keeps coming up with the message . Parse error: parse error, unexpected '='
Can anyone correct this code for me? Unfortunatly my friend has gone on holiday now so I cannot contact him.What line is it saying the error is on?if($count) = 1){change it to


if($count) == 1){Ive done that before then it comes up with this error.
Parse error: parse error, unexpected T_IS_EQUAL
( on the same line )oh yah, here you go

if($count == 1){

sorry bout thatits all working now, apart from one thing.
} else {
print "Invalid Download ";
}
the script works ok once ive took that out, but I would like to have this in.
Parse error: parse error, unexpected '}'
that is the error which comes up for it. Its on this line,
} else {make this line
header("Location: Download s/$file.jpg")

this
header("Location: Download s/$file.jpg");i know this bit is probably easier than that bit, but how do I get it to show how many people have Download ed it lol, I only just remembered about that bit :POn the page you want to display the number do something like this:

$sql = "SELECT * FROM tablename";

//build results and loop through them
while($result = mysql_fetch_object($sql)){
echo '<a href=http://www.htmlforums.com/archive/index.php/"linkout.php?id='.$result->$id.'">Download file</a> | '.$result->count.'<br />'
}
 
Back
Top