Page 2 of 2

Re: Count Downloads?

Posted: Tue Jul 12, 2011 10:04 pm
by Dummy1912
mandai wrote:
You could use a server side PHP script to keep track of the downloads, then you can use a meta tag to redirect to the file:
Code: Select all
<meta http-equiv="refresh" content="2; url=file.zip">
<?php

$count = file_get_contents("counter.txt") or die("could not read counter.txt");
echo $count . " downloads so far";
$count++;
file_put_contents("counter.txt", $count) or die("could not write counter.txt");

?>
Hi mandai,

hmmm so how do i use this in my php because theres already a code
should i pm you? so you can change it or whats wrong with it
i know it works when i press the download
but i can't show it in to the current label : Downloaded: ?

thanks
Dummy1912

Re: Count Downloads?

Posted: Wed Jul 13, 2011 12:16 am
by mandai
If you are only interested in getting the value you should download the counter.txt file directly.

Re: Count Downloads?

Posted: Wed Jul 13, 2011 9:32 am
by Dummy1912
sorry mandai
but i must sound like a idiot because i don't get it what you are talking about?

i only need to read the value from all the downloads and show them in a label
in the current .html page.

cryer; didn't know this gonna be so difficult


Dummy1912

Re: Count Downloads?

Posted: Wed Jul 13, 2011 11:34 am
by mandai
This PHP script will show the download count on the current page, as long as your server supports PHP. When you say label what HTML tag are you talking about?

Re: Count Downloads?

Posted: Wed Jul 13, 2011 11:48 am
by Dummy1912
mandai wrote:
This PHP script will show the download count on the current page, as long as your server supports PHP. When you say label what HTML tag are you talking about?
like the image :D

Re: Count Downloads?

Posted: Wed Jul 13, 2011 1:15 pm
by mandai
You just need to put the PHP script in that area of the document body.

Re: Count Downloads?

Posted: Wed Jul 13, 2011 1:26 pm
by Dummy1912
mandai wrote:
You just need to put the PHP script in that area of the document body.
:? seems not really to work :(

Re: Count Downloads?

Posted: Sun Jul 17, 2011 7:05 am
by mikethedj4
You could do this in JS.

Here's a simple script, but I didn't add the cookie option so it'll revert back to 0 on page is reloaded, or visited. Just each time you press the "Download" button it'll add 1 to the counter.

I'm sure you guys can add onto this, but it's something simple, and maybe will help others.
Code: Select all
<html>
<head>
<title>Download Counter</title>
<script type="text/javascript">
function counter(field) {
	field.value = Number(field.value) + 1;
}
</script>
</head>
<body>
	<form name="downloadcounter">
		<input type="button" value="Download" onclick="counter(downloads);">
		<input type="text" name="downloads" value="0" size="5" style="border:0px;">
	</form>
</body>
</html>
If you wanna learn how to add cookies, and such look here.

However if you want to write a hitcounter that records hits from any and all users; you cannot use Javascript - it can't write data to anywhere except cookies, which are unique to each user's browser.

So, you'll have to use some serverside application/script/method to record data permanantly at your server.
[source]

So you're better off using PHP, or Ajax for this.

Re: Count Downloads?

Posted: Sun Jul 17, 2011 9:53 am
by Dummy1912
oops

Re: [Solved] Count Downloads?

Posted: Sun Jul 17, 2011 10:40 am
by Dummy1912
Hello guys,

Sorry i can't lock this topic :(
don't have the function anymore i see cryer;

but thanks to you all
i have found it :D


thanks offc to mikethedj4
for the links i have visit and find the right thing clapper;


thanks guys.

Dummy1912

p.s

Codenstuff please can you lock this topic?