Hola:
He optado por el método del archivo.txt que parece más fácil pero no logro contar nada.
Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<style type="text/css">
<!--
.Estilo1 {color: #FFFFFF}
-->
</style>
</head>
<body>
<p class="Estilo1">.</p>
<p class="Estilo1">.</p>
<p class="Estilo1">.</p>
<p class="Estilo1">.</p>
<table width="520" border="10" align="center" cellpadding="1" cellspacing="1">
<tr>
<td colspan="4"><h1 align="center">Electrónica Pic</h1></td>
</tr>
<tr>
<td>Manual</td>
<td colspan="3"><div align="center">Formatos</div></td>
</tr>
<tr>
<td width="161"><div align="left">Minicom</div></td>
<td width="112"><div align="center"><a href="manual/minicom.pdf" target="_blank">PDF</a></div></td>
<td width="112"><div align="center"><a href="manual/minicom.xps" target="_blank">XPS</a></div></td>
<td width="112"><div align="center"><a href="http://www.pic16f84a.org/component/docman/doc_download/38-minicom-v110.html">ZIP</a>(pdf)</div></td>
</tr>
<tr>
<td><div align="left">WinPic800</div></td>
<td><div align="center">PDF</div></td>
<td><div align="center">XPS</div></td>
<td><div align="center"><a href="http://www.pic16f84a.org/component/docman/doc_download/41-winpic800-v11.html">ZIP</a>(pdf)</div></td>
</tr>
</table>
<p>
<?php
//"file_id" es el numero de la descarga
$fp= fopen( "micontador.txt", "r" );
$i=0; //contador de ID's
$big_buffer=""; //buffer gigante donde almacenamos todo el archivo
while( !feof($fp) )
{
$buf= fgets($fp);
if( $i==$_GET["file_id"] ) //si estamos leyendo el ID a descargar
{
$x= explode( "|", $buf ); //explotamos/partimos buffer por el delimitador
$big_buffer .= $x[0]; //concatenamos archivo
$big_buffer .= "|"; //concatenamos delimitador
$big_buffer .= ($x[1]+1); //concatenamos aumento +1 del contador
echo file_get_contents( $x[0] ); //proporcionamos descarga
unset($x);
}
else
$big_buffer .= $buf; //concatenamos buffer directo
unset($buf); //limpiamos buffer
$i++; //incrementamos
}
fclose($fp); //cerramos archivo
unset($fp); //limpiamos fp
$fp_out= fopen( "micontador.txt", "w" ); //abrimos archivo eliminando todo su contenido
fwrite($fp_out, $big_buffer); //escribimos el buffer gigante
fclose($fp_out);
unset($fp_out); //limipiamos fp
unset($big_buffer); //limpiamos buffer
?>
</p>
</body>
</html>
La web de prueba es esta:
http://usuarios.lycos.es/electronicapic/index.php