Page 1 of 1

download count with textfile

Posted: Sun Aug 10, 2003 1:00 pm
by kLaNt
:?:

Hi

Hope you can help me fast here, tried many forums without succes. Im a newbie in php.
On my homesite i have several freeware program that ive coded. I have every prg on a seperate page. To download the prg the visitor must click on a image to start download the file (using a href). What i want is that when the user click the image i want a following code to execute

<?php
$fp=fopen("theprogram.txt","r");
$count=fgets($fp,1024);
fclose($fp);
$fw=fopen("theprogram.txt","w");
$countnew=fputs($fw,$count+1);
fclose($fw);
?>

then the textfile increase the number with one, want to see how many downloads i have.
I have no problem to read and put the contents from the file to see downloadsnumber but i dont know how to put above code in my htmlcode.
Ive tried in onclick but dont execute.

Please solve this problem before all my hair is gone :-)

Posted: Sun Aug 10, 2003 1:52 pm
by JAM
You 'could'...

Use refer the user to a different page, say:
http://ww.example.com/files/download.php?file=niceapp

In folder /files/ you make the download.php file. And in that you can insert your script, and tweak it so that instead of a static filename, you use $_GET['file'].'.txt' if you want one txt-file for each application.

On the download page, you can then show some
"Downloading will start in 5 sec. if you dont want to wait click this link..."
and the downloading can begin.

Just ideas...