Ver Mensaje Individual
  #6 (permalink)  
Antiguo 25/10/2005, 01:26
rayder
 
Fecha de Ingreso: agosto-2004
Mensajes: 118
Antigüedad: 22 años, 1 mes
Puntos: 1
Si te digo la verdad, no veo donde está el error.

Te pongo una función que está sacada de este foro y que utilizo en algunos sitios web.
Código PHP:
function descargaFichero ($fichero)
        { 
// HEADERS SACADAS DE PHPMYADMIN
        
$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';

        
// Esta funcion esta operativa desde php 4.3.0 y parece ser que tiene buena pinta arreglando el nombre de los 
        // ficheros y las extensiones
        //$mime_type=mime_content_type ($fichero);
        
        
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);
        exit();
        } 
Esta función te permite pasarle una ruta de descarga, incluyendo escalado de directorios o construcciones dinamicas desde base de datos. El único problema que tiene, es que cuando el navegador en netscape y derivados, al fichero descargado le añade la extensión .php