Ver Mensaje Individual
  #1 (permalink)  
Antiguo 27/01/2009, 15:20
evoarte
 
Fecha de Ingreso: julio-2002
Mensajes: 813
Antigüedad: 22 años, 8 meses
Puntos: 2
forzar descarga - archivo no permitido

buenas noches,

utilizo este código para forzar la descarga del archivo:

<%@language=javascript%>
<% Response.Buffer=true %>

<%

var strFilePath;
var strFileSize;
var strFileName;

var adTypeBinary = 1;

//strFilePath = Request.QueryString("file");
//strFileSize = Request.QueryString("size");
strFileName = String(Request.QueryString("name"));

Response.Write(strFileName);

Response.Clear();

var ruta = "\\pdf\\" + strFileName;

objStream = Server.CreateObject("ADODB.Stream");
objStream.Open();
objStream.Type = adTypeBinary;
objStream.LoadFromFile(Server.MapPath(ruta));

strFileType = strFileName.substr(strFileName.length-4);

switch (strFileType)
{
case ".asf":
ContentType = "video/x-ms-asf";
break;
case ".avi":
ContentType = "video/avi";
break;
case ".doc":
ContentType = "application/msword";
break;
case ".zip":
ContentType = "application/zip";
break;
case ".xls":
ContentType = "application/vnd.ms-excel";
break;
case ".gif":
ContentType = "image/gif";
break;
case ".jpg":
ContentType = "image/jpeg";
break;
case "jpeg":
ContentType = "image/jpeg";
break;
case ".wav":
ContentType = "audio/wav";
break;
case ".mp3":
ContentType = "audio/mpeg3";
break;
case ".mpg":
ContentType = "video/mpeg";
break;
case "mpeg":
ContentType = "video/mpeg";
break;
case ".rtf":
ContentType = "application/rtf";
break;
case ".htm":
ContentType = "text/html";
break;
case "html":
ContentType = "text/html";
break;
case ".asp":
ContentType = "text/asp";
break;
case ".pdf":
ContentType = "application/pdf";
break;
default:
ContentType = "application/octet-stream";
}

Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);
Response.AddHeader("Content-Length", strFileSize);

Response.Charset = "UTF-8";
Response.ContentType = ContentType;

Response.BinaryWrite(objStream.Read);
Response.Flush();

objStream.close();
objStream = null;
%>

el archivo existe, en la carpeta \pdf\Pedido32.pdf, está bien construido (con fpdf para asp), el problema viene cuando fuerzo la descarga: cuando se abre la ventana de descarga:

Nombre:Pedido32.pdf
Tipo: Adove Acrobat Document
De: www.midominio.es

Tanto si intento abrirlo directamente o lo guardo para luego abrirlo:

Acrobat Reader no puede abrir 'Pedido32.pdf' por que no es un tipo admitido o está dañado.

He probado a abrir el archivo guardado en el web, y el archivo está bien,

saben de que se trata?

un saludo,
josé carlos.