Comunidad de diseño web y desarrollo en internet online

Siempre se corta Forzar Descarga

Citar            
MensajeEscrito el 01 Oct 2008 12:18 pm
Buenas,

ME he leido los dos tutos sobre forzar descargas en flash mediante php y tengo un problema. Las descargas siempre se cortan antes de terminar sobre todo con ficheros grandes (un .zip de 68MB) y tambien con mp3 de unos 4MB. Con los codigos de los tutos que utilizan readfile() se me corta a los 300k mas o menos, con este codigo que saque de php.net he conseguido descargar algun mp3 completo y unos 25mb del .zip pero entero nunca:

Código :

<?php

    $f = "../descargas/" . $_GET["archivo"];
    $file_extension = strtolower(substr(strrchr($f,"."),1));
    
    switch($file_extension)
    {

         case "mp3":
         
             header('Content-Description: File Transfer');
             header('Content-Type: audio/mp3');
             header('Content-Disposition: attachment; filename='.basename($f));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
              header('Content-Length: ' . filesize($f));
      
             readfile_chunked($f);
             
             break;
       
        
        case "zip":
           
              header('Content-Description: File Transfer');
             header('Content-Type: application/zip');
             header('Content-Disposition: attachment; filename='.basename($f));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
              header('Content-Length: ' . filesize($f));
      
             readfile_chunked($f);
             
             break;
             
       case "jpg":
       
              header('Content-Description: File Transfer');
             header('Content-Type: image/jpg');
             header('Content-Disposition: attachment; filename='.basename($f));
             header('Content-Transfer-Encoding: binary');
             header('Expires: 0');
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
              header('Content-Length: ' . filesize($f));
      
             readfile_chunked($f);
             
             break;          
             
       }
     
     
    
function readfile_chunked($filename,$retbytes=true) 
{ 
   $chunksize = 1*(1024*1024); // how many bytes per chunk 
   $buffer = ''; 
   $cnt =0; 
   $handle = fopen($filename, 'rb'); 
   if ($handle === false) 
   { 
       return false; 
   } 
   while (!feof($handle)) 
   { 
       $buffer = fread($handle, $chunksize); 
       echo $buffer; 
       ob_flush(); 
       flush(); 
       if ($retbytes) 
       { 
           $cnt += strlen($buffer); 
       } 
   } 
   $status = fclose($handle); 
   if ($retbytes && $status) 
   { 
       return $cnt; // return num. bytes delivered like readfile() does. 
   } 
   return $status; 

} 
?>


¿Alguien puede ver en que estoy fallando?

Por S3rL0l

3 de clabLevel



 

msie7
Citar            
MensajeEscrito el 01 Oct 2008 12:36 pm
Prueba haciendo readfile($f) en vez de readfile_chunked($f);

Jorge

Por solisarg

BOFH

13669 de clabLevel

4 tutoriales
5 articulos

Genero:Masculino   Bastard Operators From Hell Premio_Secretos

Argentina

firefox
Citar            
MensajeEscrito el 01 Oct 2008 02:34 pm
Como comentaba en el post con readfile() no llega siquiera a los 300k, he probado tambien a poner al principio del script el set_time_limit(0); por alguna recomendacion que he leido pero sigue pasando lo mismo.

Por S3rL0l

3 de clabLevel



 

msie7

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.