Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/05/2012, 15:34
fernandog07
 
Fecha de Ingreso: mayo-2012
Mensajes: 7
Antigüedad: 12 años
Puntos: 0
Pregunta Alternativa fseek para archivos remotos

Hola,

Tengo un problema, Tengo unos archivos de video en http://mycaja.com/media/video.mkv, El problema es que intento hacer un streaming de el video en http://midominio.com/portal.php?id=123456.

fseek() me devuelve un error = PHP Warning: fseek() [<a href='function.fseek'>function.fseek</a>]: stream does not support seeking in ...

Lo que pude averiguar buscando en internet es que fseek solo funciona para archivos locales (lo cual no es conveniente para mi), Mi pregunta es, hay alguna otra alternativa para esto?, estoy investigando sobre CURL pero no entiendo muy bien como funciona.

Lo que tengo es que una vez iniciada la descarga, utilizo el $_SERVER['HTTP_RANGE'] para obtener el rango de bytes que necesito descargar.

Código PHP:
$file $media['media_link'];
                                
                if (
fileExists($file)){
                    
                    
//get headers
                    
$headers get_headers($file1);
                    
$file_size $headers['Content-Length'];
                    
$file_extension file_extension($file);
                    
$partial_content false;
                    
$start 0;
                    
$end = -1;
                    
                    
//Check if it's a range request
                    
if (isset($_SERVER['HTTP_RANGE'])) {
                        
$partial_content true;
                        
$http_range substr($HTTP_SERVER_VARS['HTTP_RANGE'] , strlen('bytes='));
                        
$range explode("-"$http_range);
                        
$start intval($range[0]);
                        
$end intval($range[1]);
                        
//send headers for partial content
                        
header('HTTP/1.0 206 Partial Content'); 
                        
header('Status: 206 Partial Content'); 
                        
header('Accept-Ranges: bytes'); 
                        
header("Content-Range: bytes $start-$end/".$file_size);
                    }
                    
                    
//Send headers
                    
$file_chunk $end $start 1;

                    
header('Content-Length: '.$file_chunk);
                    
header('Content-Description: File Transfer');
                    
header('Content-type: '.content_type($extension));
                    
header('Content-Disposition: inline; filename='.$file);
                    
header('Content-Transfer-Encoding: binary');
                    
                    
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
                    
                    
                    
//Open file
                    
$file_open fopen($file'rb');

                    
fseek($file_open$start);
    
                    while(!
feof($file_open)){
                        
set_time_limit(0);
                        print(
fread($file_open1024*8));
                        
flush();
                        
ob_flush();
                    }
    
                    
fclose($file_open); 
Antes de esto utilizaba readfile y funcionaba de maravilla, solo que no podría hacer streaming progresivo ya que el header no era parcial.

Espero que puedan ayudarme, saludos!