Pues veras, ya casi me voy a dormir pero alcance a crear de a flash gordon este ejemplillo basado en alguno de la red, lo modifique muy poco y aqui esta el resultado:
<?php
$path = $_SERVER['DOCUMENT_ROOT']."/Contador/"; // change the path to fit your websites document structure
$FileCounter = $_SERVER['DOCUMENT_ROOT']."/Contador/counter.txt"; //change for your own file counter
$fullPath = $path.$_GET['download_file']; // set method GET for download_file, you can rename it.
$nCounterNRar = (int)0; // Set to zero this variable
$nCounterNZip = (int)0; // Set to zero this variable
$nCounterNIso = (int)0; // Set to zero this variable
$nCounterNApz = (int)0; // Set to zero this variable
// if your file does exists then delete this to...
//Create the file if not exists.
if(!$fileCounterOpen = fopen($FileCounter, "r")) {
$fileCounterOpenCreate = fopen($FileCounter, "w"); //...
fwrite($fileCounterOpenCreate, "DownloadsRar=0" . "\r\n". "DownloadsZip=0" . "\r\n" . "DownloadsApz=0"); // write contents //...
fclose($fileCounterOpenCreate); //...
}
// this.
//if the file already (has been created manually) exists just remove the else and let the condition if
//if($fileCounterOpen)
else {
$Content = file_get_contents($FileCounter); // get contents
$nCounter = explode("=", $Content); // explode gets contents separated by delimiters
$nCounterNRar = (int)$nCounter[1]; // get second value, in this case first value is Downloads and second the number, (int) means it will be an integer
$nCounterNZip = (int)$nCounter[2];
$nCounterNApz = (int)$nCounter[3];
fclose($fileCounterOpen); // close the readed file
if ($nCounterNRar >= 0) // be sure already have a number to proceed
{
//$fileCounterOpenCreate = fopen($FileCounter, "w"); // reopen the same file but in this case to write it
if($fileCounterOpenCreate = fopen($FileCounter, "w")) // verify if can open
{
if ($fd = fopen ($fullPath, "r")) {
$fsize = filesize($fullPath);
$path_parts = pathinfo($fullPath);
$ext = strtolower($path_parts["extension"]);
switch ($ext) {
case "rar":
header("Content-type: application/rar");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Pragma: no-cache");
$nCounterNRar = (int)$nCounterNRar + 1;
$nCounterNZip = (int)$nCounterNZip;
$nCounterNIso = (int)$nCounterNIso;
$nCounterNApz = (int)$nCounterNApz;
break;
case "zip":
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Pragma: no-cache");
$nCounterNRar = (int)$nCounterNRar;
$nCounterNZip = (int)$nCounterNZip + 1;
$nCounterNIso = (int)$nCounterNIso;
$nCounterNApz = (int)$nCounterNApz;
break;
case "apz":
header("Content-type: application/apz");
header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");
header("Pragma: no-cache");
$nCounterNRar = (int)$nCounterNRar;
$nCounterNZip = (int)$nCounterNZip;
$nCounterNIso = (int)$nCounterNIso;
$nCounterNApz = (int)$nCounterNApz + 1;
break;
default;
header("Content-type: application/octet-stream");
header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
header("Pragma: no-cache");
break;
}
header("Content-length: $fsize");
header("Cache-control: private"); //use this to open files directly
while(!feof($fd)) {
$buffer = fread($fd, 4096);
echo $buffer;
}
}
fwrite($fileCounterOpenCreate, "DownloadsRar=" . ($nCounterNRar) . "" . "\r\n" . "DownloadsZip=" .($nCounterNZip). "" . "\r\n" . "DownloadsApz=" . ($nCounterNApz) . "");
fclose($fileCounterOpenCreate);
fclose ($fd);
//fwrite($fileCounterOpenCreate, 'Downloads=' . ($nCounterNRar + 1)); // auto increment of the initial value
//print("Descargado: " . $nCounterNRar + 1);
//echo "Descargado: " . $nCounterNRar + 1;
exit;
}
}
}
?>
Es muy basico y la verdad ahora no tengo tiempo de explicarlo, lo que hace es generarte un fichero de texto y guardarte tres tipos de descargas (rar, zip, apz), solo create un Form en tu fichero index.php y algun boton para iniciar la descarga, el campo donde mostrara el total de las descargas y demas, los parametros son de facil comprension, si puedo luego te explico todo el rollo, le puse algo en ingles, aparte de lo que el creador del codigo le puso, espero entiendas algo.
Quiza tenga muchas discrepancias pero al menos a mi me jalo bonito, ya regreso luego y lo modificare para que quede mas perron.
Saludos.