readfile
| From: | Jose Corbacho | Date: | Thu, 06 May 2004 11:54:38 +0000 |
| Subject: | readfile | ||
| Groups: | php.general.es | ||
| Request: | Send a blank email to general-es+get-48299@lists.php.net to get a copy of this message | ||
Hola,
Tengo una página para descargar ficheros a partir de un parametro dado: http://miserver/donwload.php?id=45
En ese momento se busca en la base de datos el id=45 para obtener el path real del fichero y luego con unas cuantas cabeceras header y el readfile le comienza la descarga.
El problema que tengo es que mis ficheros a descargar son bastante grandecitos y hasta que no termina la descarga entera del fichero, la web no es navegable. Alguna idea sobre como solucionar esto??
El código implementado mas o menos es este:
$filename=basename($fichero);
$filesize = filesize($fichero);
// 'application/octet-stream' is the registered IANA type but
// MSIE and Opera seems to prefer 'application/octetstream'
$USR_BROWSER_AGENT="";
if (preg_match('@Opera(/| )([0-9].[0-9]{1,2})@', $_SERVER['HTTP_USER_AGENT'])) $USR_BROWSER_AGENT='OPERA';
if (preg_match('@MSIE ([0-9].[0-9]{1,2})@', $_SERVER['HTTP_USER_AGENT'])) $USR_BROWSER_AGENT='IE';
$mime_type = ($USR_BROWSER_AGENT == 'IE' || $USR_BROWSER_AGENT == 'OPERA')
? 'application/octetstream'
: 'application/octet-stream';
header('Content-Type: ' . $mime_type);
// Se informa al navegador del tamaño del fichero y puede mostrar la barra de progreso de descarga
header('Content-Length: ' . filesize($fichero));
header('Content-Transfer-Encoding: binary');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
// IE need specific headers
if ($USR_BROWSER_AGENT == 'IE')
{
//header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
}
else
{
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Pragma: no-cache');
}
@readfile ($fichero);