Ver Mensaje Individual
  #9 (permalink)  
Antiguo 09/09/2015, 11:20
alonsomaxx
 
Fecha de Ingreso: julio-2012
Mensajes: 81
Antigüedad: 11 años, 8 meses
Puntos: 3
Respuesta: Error descarga archivos

Mejor así...

Enlace:
<a href="index.php?ctl=descargas&archi=archivo">Desca rgar Archivo</a>

Controlador:
Código PHP:
function misDescargas(){
            
$sec=new secciones();            
            
$sec->Downloads();
        } 

Clase secciones:
Código PHP:
<?php
class secciones{
    function 
Downloads() {
        if (!isset(
$_GET['archi']) || empty($_GET['archi'])) {
            exit();
        }
        
        
$root "download/";
        
$file basename($_GET['archi']);
        
$path $root $file.".zip";      
        
$type '';

        if (
is_file($path)) {
            
$size filesize($path);
            
            if (
function_exists('mime_content_type')) {
                
$type mime_content_type($path);
                
            } else if (
function_exists('finfo_file')) {
                
$info finfo_open(FILEINFO_MIME);
                
$type finfo_file($info$path);
                
finfo_close($info);
            }
            if (
$type == '') {
                
$type "application/force-download";
            }
            
// Definir headers
            
            
header("Content-Type: $type");
            
header("Content-Disposition: attachment; filename=$file.zip");
            
header("Content-Transfer-Encoding: binary");
            
header("Content-Length: " $size);  //Esta linea da error en localhost
            // Descargar archivo
            
readfile($path);
            exit();
        } else {
            die(
"El archivo no existe.");
        }
    }
}
?>