Implementé una solución similar en un sitio web de alojamiento de archivos.
Lo que quiere hacer es utilizar la función de devolución de llamada register_shutdown_function que le permite detectar el final de la ejecución de un script php independientemente del resultado.
Luego desea tener su archivo en una ubicación no accesible en la web de su servidor (s), y hacer que sus descargas pasen por php: la idea es que usted quiere poder rastrear cuántos bytes se han pasado a el cliente.
Aquí está una manera básica de la aplicación (por ejemplo :)
<?php
register_shutdown_function('shutdown', $args);
$file_name = 'file.ext';
$path_to_file = '/path/to/file';
$stat = @stat($path_to_file);
//Set headers
header('Content-Type: application/octet-stream');
header('Content-Length: '.$stat['size']);
header('Connection: close');
header('Content-disposition: attachment; filename='.$file_name);
//Get pointer to file
$fp = fopen('/path/to/file', 'rb');
fpassthru($fp);
function shutdown() {
$status = connection_status();
//A connection status of 0 indicates no premature end of script
if($status == 0){
//Do whatever to increment the counter for the file.
}
}
>?
es evidente que hay maneras de mejorar, así que si usted necesita más detalles u otro comportamiento, por favor hágamelo saber!
¿Cómo se supone que esos archivos son grandes? Kb? ¿Megabyte? <100 Mb? – Strae
DK-Wamp dijo: "¿Puedo obtener más detalles sobre este tema? // Intenté utilizar este script pero no funcionó para mí .((() Sé que es un tema antiguo, pero espero encuentra una solución. " – Veedrac