Three files will be used:
1 - main.php, which will display the download link and the number of downloads
2 - download_arquivo.php - This will increase the counter by 1, will download the file and redirect to main.php
3 - counter_file.txt - It will store the number of downloads
FILE 1 - MAIN.PHP:
<html>
<body>
<a href="download_arquivo">DOWNLOAD AQUI</a>
<br>N. de Downloads: <? include "contador_arquivo.txt"; ?>
</body>
</html>
ARCHIVE 2 - DOWNLOAD_ARQUIVO.PHP
<html>
<body>
<a href="java script:history.back(-1)">">Voltar</a>
<?php
//Abre o contador de downloads e acrescenrta em 1
$fp = fopen("contador_arquivo.txt","r");
$visitas = fgets($fp,255);
$visitas++;
fclose($fp);
$fp = fopen("contador_arquivo.txt","w+");
fwrite($fp, $visitas);
fclose($fp);
?>
<script language="JavaScript">
//Redireciona para o arquivo de download
location.href="SEU_ARQUIVO.ZIP";
</script>
FILE 3 - ARCHIVER.TXT
(escreva o numero 0 e salve o arquivo)
Source: Counter Clicks