Ver Mensaje Individual
  #13 (permalink)  
Antiguo 15/06/2006, 15:23
Avatar de mveraa
mveraa
 
Fecha de Ingreso: diciembre-2002
Ubicación: santiago-chilito
Mensajes: 1.931
Antigüedad: 21 años, 3 meses
Puntos: 2
hola no comprendo tu punto , ya que solo pruebo con la funcion para descarga un .doc que tengo en el server, aun no estoy considerando ninguna validacion de usuario.

yo solo hago esto .

<?php


function download( $file, $fname="" ) {

if( empty( $fname ) ) {
$fname = explode( "/", $file );
$fname = $fname[count($fname)-1];

}

if( !file_exists( $file ) ) {
header("HTTP/1.1 404 Not Found");
return;
}

$fsize = filesize($file);
$bufsize = 20000;

if(isset($_SERVER['HTTP_RANGE'])) { // Partial Download
if(preg_match("/^bytes=(\\d+)-(\\d*)$/", $_SERVER['HTTP_RANGE'], $matches)) { //parsing Range header
$from = $matches[1];
$to = $matches[2];
if(empty($to)) {
$to = $fsize - 1; // -1 because end byte is included
//(From HTTP protocol:
// 'The last-byte-pos value gives the byte-offset of the last byte in the range; that is, the byte positions specified are inclusive')
}
$content_size = $to - $from + 1;
header("HTTP/1.1 206 Partial Content");
header("Content-Range: $from-$to/$fsize");
header("Content-Length: $content_size");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$fname");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: private");

if($fh = fopen($fpath, "rb")) {
fseek($fh, $from);
$cur_pos = ftell($fh);
while($cur_pos !== FALSE && ftell($fh) + $bufsize < $to+1) {
$buffer = fread($fh, $bufsize);
print $buffer;
$cur_pos = ftell($fh);
}

$buffer = fread($fh, $to+1 - $cur_pos);
print $buffer;

fclose($fh);
} else {
header("HTTP/1.1 500 Internal Server Error");
return;
}
} else {
header("HTTP/1.1 500 Internal Server Error");
return;
}
} else { // Usual download
header("HTTP/1.1 200 OK");
header("Content-Length: $fsize");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$fname");
header("Content-Transfer-Encoding: binary");
header("Cache-Control: private");

$fh = fopen($fpath, "rb");

while($buf = fread($fh, $bufsize))
print $buf;

fclose($fh);
}
}

//"../prueba_donwload/tu.txt"

$file_to_dl = "../prueba_donwload/tu.txt";
download( $file_to_dl );
exit();
?>
__________________
"Cuando se adelanta un oponente, enfréntalo y salúdalo; si intenta retroceder, déjalo seguir su camino"