Estuve revisando las FAQ's y me encontré con un script para realizar descargas. La cosa es que lo he convertido en una función y me ha quedado así:
Código PHP:
function Download($filename){
$headers = $_SERVER['HTTP_RANGE'];
if ($headers[Range]){
$pos=strpos ($headers[Range], "bytes=");
$pos2=strpos($headers[Range],"-");
$bytes=substr ($headers[Range], $pos+strlen("bytes="),$pos2-($pos+strlen("bytes=")));
}else{
$bytes=0;
}
settype ($bytes, "integer");
$tarchivo=filesize($filename) - $bytes;
$ttotal=filesize($filename);
error_reporting(0);
header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($filename)));
header("Accept-Ranges: bytes");
header("Content-Length: ". $tarchivo);
header("Content-Disposition: attachment; filename="."archivo.exe");
header("Content-Range: bytes ".$bytes."-".($ttotal-1)."/".$ttotal);
header("Content-Type: application/octet-stream");
$fp = fopen($filename,'rb');
if (!$fp) {
echo "Error abriendo el archivo $filename";
exit();
}
rewind ($fp);
fseek ($fp, $bytes);
if(!fpassthru($fp)) {
echo "Error de salida";
exit();
}
header("Connection: close");
exit();
}
lo que quiero hacer y no se como es poner el nombre real al archivo, o sea, cuando trato de descargar cualquier archivo por ejemplo file01.zip me lo trata de de descargar pero me le pone por defecto a la descarga archivo.exe y lo que quiero que ponga es file01.zip. Probe de esta forma:
Código PHP:
header("Content-Disposition: attachment; filename=".$filename."");
pero entonces me pone el nombre de la pagina en cuestion o sea descarga.php
me ayudan a ver que pasa?
Salu2