Foros del Web » Programando para Internet » PHP »

Filesize no me funciona

Estas en el tema de Filesize no me funciona en el foro de PHP en Foros del Web. Buenas que tal hice un sistema de descargas para un cliente, cual es mi sorpresa que al descargar el archivo, en la ventana de descargas ...
  #1 (permalink)  
Antiguo 20/09/2012, 04:57
 
Fecha de Ingreso: agosto-2010
Ubicación: Barcelona
Mensajes: 22
Antigüedad: 13 años, 8 meses
Puntos: 0
Exclamación Filesize no me funciona

Buenas que tal hice un sistema de descargas para un cliente, cual es mi sorpresa que al descargar el archivo, en la ventana de descargas me sale "tiempo restante desconocido".

No hay manera de que me coja el tamaño del archivo, os dejo el php que use, a ver si veis un error o me podeis hechar un cable!


PHP que acciona la descarga y el envio de email!
Código PHP:
<?php
    session_start
();
    if(isset(
$_SESSION["variables_form"]) && isset($_SESSION["variables_form_dw"]) && isset($_REQUEST["so"]) && isset($_REQUEST["file"])){  
        
$variables_form $_SESSION["variables_form_dw"];
        
$variables_form["so"] = $_REQUEST["so"];

        
$_SESSION["variables_form_dw"] = $variables_form;
         
$name stripslashes(strip_tags($variables_form["nombre"]))." ".stripslashes(strip_tags($variables_form["apellidos"]));
        
$apellidos stripslashes(strip_tags($variables_form["apellidos"]));
         
$empresa stripslashes(strip_tags($variables_form["empresa"]));
        
$telefono stripslashes(strip_tags($variables_form["telefono"]));
        
$mail stripslashes(strip_tags($variables_form["mail"]));
        
$npeces stripslashes(strip_tags($variables_form["npces"]));
        
$producto stripslashes(strip_tags($variables_form["producto"]));
        
$sistema stripslashes(strip_tags($variables_form["so"]));
        
        
$ip .= ""$_SERVER['REMOTE_ADDR'] ."";
        
        
$headers_fromUser "From: ".$name."\r\n";
        
$headers_fromUser.= "Reply-To: ".$mail."\r\n";
        
$headers_fromUser.= "MIME-Version: 1.0\r\n";
        
$headers_fromUser.= "Content-Type: text/html; charset=UTF-8\r\n";
        
        
$message "IP: ".$ip."<br /> Nombre: ".$name."<br />Apellidos: ".$apellidos."<br />Empresa: ".$empresa."<br />Teléfono: ".$telefono."<br />Email: ".$mail."<br />Nº PCs: ".$npeces."<br />Producto: ".$producto."<br />Sistema: ".$sistema;
    
        
$send = @mail("Totem Guard"." <[email protected]>\r\n","Descarga de software"$message$headers_fromUser);

        
            
$url $_REQUEST["file"];
            
            
$file basename($url);
            
$size filesize($path); 
            
//decomentada la seguent linea
            //$size = filesize($url);
            
            
            
            
$mime = array('application/octet-stream'); 
            
            
header('Content-Type: '.$mime);
            
header('Content-Disposition: attachment; filename="'.$file.'"');
            
header('Content-Transfer-Encoding: binary');
            
//header('Content-Length: '.sprintf('%d', $size));
            
header('Expires: 0');  
            
            
// check for IE only headers
            
if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) {
                
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                
header('Pragma: public');
            } else {
                
header('Pragma: no-cache'); 
            } 

           
            
    
readfile($url);
            if (!
$send) {
                
                die();
            }
    
    }
    else if(!isset(
$_REQUEST["producto_id"])){ 
        
$error_form "Debe seguir todos los pasos para poder descargar el software. Debe volver a rellenar el <a href='http://www.xxx.com'>formulario</a>.";
    }
    
    
?>

Gracias, Christian!
  #2 (permalink)  
Antiguo 20/09/2012, 05:08
 
Fecha de Ingreso: agosto-2010
Ubicación: Barcelona
Mensajes: 22
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Filesize no me funciona

El archivo de descarga es de una web externa, puede ser la causa?
  #3 (permalink)  
Antiguo 20/09/2012, 10:16
 
Fecha de Ingreso: agosto-2010
Ubicación: Barcelona
Mensajes: 22
Antigüedad: 13 años, 8 meses
Puntos: 0
Respuesta: Filesize no me funciona

Solucionado!

el código final fue!

Código PHP:
Ver original
  1. <?php
  2.     session_start();
  3.     if(isset($_SESSION["variables_form"]) && isset($_SESSION["variables_form_dw"]) && isset($_REQUEST["so"]) && isset($_REQUEST["file"])){  
  4.         $variables_form = $_SESSION["variables_form_dw"];
  5.         $variables_form["so"] = $_REQUEST["so"];
  6.  
  7.         $_SESSION["variables_form_dw"] = $variables_form;
  8.          $name = stripslashes(strip_tags($variables_form["nombre"]))." ".stripslashes(strip_tags($variables_form["apellidos"]));
  9.         $apellidos = stripslashes(strip_tags($variables_form["apellidos"]));
  10.          $empresa = stripslashes(strip_tags($variables_form["empresa"]));
  11.         $telefono = stripslashes(strip_tags($variables_form["telefono"]));
  12.         $mail = stripslashes(strip_tags($variables_form["mail"]));
  13.         $npeces = stripslashes(strip_tags($variables_form["npces"]));
  14.         $producto = stripslashes(strip_tags($variables_form["producto"]));
  15.         $sistema = stripslashes(strip_tags($variables_form["so"]));
  16.        
  17.         $ip .= "". $_SERVER['REMOTE_ADDR'] ."";
  18.        
  19.         $headers_fromUser = "From: ".$name."\r\n";
  20.         $headers_fromUser.= "Reply-To: ".$mail."\r\n";
  21.         $headers_fromUser.= "MIME-Version: 1.0\r\n";
  22.         $headers_fromUser.= "Content-Type: text/html; charset=UTF-8\r\n";
  23.        
  24.         $message = "IP: ".$ip."<br /> Nombre: ".$name."<br />Apellidos: ".$apellidos."<br />Empresa: ".$empresa."<br />Teléfono: ".$telefono."<br />Email: ".$mail."<br />Nº PCs: ".$npeces."<br />Producto: ".$producto."<br />Sistema: ".$sistema;
  25.    
  26.         $send = @mail("Totem Guard"." <[email protected]>\r\n","Descarga de software", $message, $headers_fromUser);
  27.  
  28.             $url = $_REQUEST["file"];
  29.            
  30.             $file = basename($url);        
  31.             $head = get_headers($url, 1);
  32.             $size = $head['Content-Length'];       
  33.             $mime = array('application/octet-stream');
  34.            
  35.             header('Content-Type: '.$mime);
  36.             header('Content-Disposition: attachment; filename="'.$file.'"');
  37.             header('Content-Transfer-Encoding: binary');
  38.             header('Content-Length: '.$size);
  39.        
  40.             header('Expires: 0');  
  41.            
  42.             // check for IE only headers
  43.             if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)) {
  44.                 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  45.                 header('Pragma: public');
  46.             } else {
  47.                 header('Pragma: no-cache');
  48.             }
  49.  
  50.            
  51.            
  52.     readfile($url);
  53.             if (!$send) {
  54.                
  55.                 die();
  56.             }
  57.    
  58.     }
  59.     else if(!isset($_REQUEST["producto_id"])){
  60.         $error_form = "Debe seguir todos los pasos para poder descargar el software. Debe volver a rellenar el <a href='http://www.xxx.com'>formulario</a>.";
  61.     }
  62.    
  63.    
  64. ?>

Etiquetas: filesize
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:46.