Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/05/2010, 08:59
juan_carlos00
 
Fecha de Ingreso: mayo-2010
Ubicación: Madrid
Mensajes: 7
Antigüedad: 14 años
Puntos: 0
Información Error al descargar un archivo

Hola compañeros
Estoy haciendo un script en php para la descarga de achivos y me hace lo siguiente: si descargo el archivo me decarga con el nombre del fichero php desde donde realiza la descarga.
y si lo que quiero es visializar dicho documnto que es en pdf me sale un error que pone "Error al abrir el documento. El archivo está dañado y no puede repararse.
pongo el codigo para ver si alguien me puede decir que puede estar pasando

<?php // File: download.php
$url=dirname(__FILE__)."/documentos/";
if (!isset($_GET['id']) || empty($_GET['id'])) {
exit();
}
$root = $url;
$file = basename($_GET['id']);
$path = $root.$file;
$type = '';
echo $path;
if (is_file($path)) {
$size = filesize($path);
if (function_exists('mime_content_type')) {
$type = mime_content_type($path);
} else if (function_exists('finfo_file')) {
$info = finfo_open(FILEINFO_MIME);
$type = finfo_file($info, $path);
finfo_close($info);
}
if ($type == '') {
$type = "application/force-download";
}
// Set Headers
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=$file");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $size);
// Download File
readfile($path);
} else {
die("File not exist !!");
}?>