1 - Put the following code into a file called "counter.php";
PHP Code:
<?php
$counter = 'path/to/counter.txt'; // text file to store download count - create manually and put a 0 (zero) in it to begin the count
$download = 'http://mywebsite.com/file/to/download.zip'; // the link to your download file
$number = file_get_contents($counter); // read count file
$number++; // increment count by 1
$fh = fopen($counter, 'w'); // open count file for writing
fwrite($fh, $number); // write new count to count file
fclose($fh); // close count file
header("Location: $download"); // get download
?>
2 - Create the text file defined in the $counter value/location above and just put a 0 (zero) in it. The sample code file is called "counter.txt".
3 - Create a download link to the "counter.php" file instead of the actual download file;
Code:
<a href="path/to/counter.php">DOWNLOAD</a>
4 - To display the download count on your web page;
PHP Code:
<?php echo file_get_contents('path/to/counter.txt');?>
Hope that helps
Bookmarks