← Foro de PHP

Bajar archivos

Hilo en el foro de PHP · 02 de Diciembre del 2003 · 2 respuestas
Javier02 de Diciembre del 2003
Pregunta
Estoy tratando de bajar un archivo con PHP usando la funcion HEADER.
pongo lo siguiente:

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Content-Transfer-Encoding: binary");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$archivo");
header("Content-Length: $size");

Pero siempre me baja el archivo mal, ocupando O bytes

que me está faltando??

Respuestas 2

Tino02 de Diciembre del 2003
$file="tuarchivo.extension";
$size=filesize($file);

header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Content-Transfer-Encoding: binary");
header("Content-type: application/force-download");
header("Content-Disposition: attachment; filename=$archivo");
header("Content-Length: $size");

Tino02 de Diciembre del 2003
$archivo="patch del archivo";
$size=filesize($archivo);
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Expires: 0");
header("Content-Transfer-Encoding: binary");
header("Content-type: application/force-download");
header("Content-Disposition: attachment;
header("Content-Length: $size");

readfile($archivo);
¿Buscas más hilos como este? Mira el foro de PHP o usa el buscador.