如何在ASP中提高“文件下载”并防止热链接

时间:2011-02-15 13:25:11

标签: asp-classic vbscript download

我在PHP中有这个代码:

header("Content-Type: application/vnd.ms-excel");
header("Content-Type: application/download");
header("Content-Length: ".filesize($path.$filename));
header("Content-disposition: attachment; filename=" . urlencode($filename));
readfile($path.$filename);

第一次,我在asp中使用它:

<%
    Response.AddHeader "content-disposition","attachment; filename=download.xls"
%>

我也阻止“hotlink”

1 个答案:

答案 0 :(得分:3)

Set ObjStr = Server.CreateObject("ADODB.Stream")
ObjStr.Type = 1 'AdBinary – Binário
ObjStr.Open

ObjStr.LoadFromFile "D:\Folder\edital.pdf"

varBuffer = ObjStr.Read

Response.buffer = true

Response.AddHeader "content-disposition","attachment;"
Response.ContentType = "application/pdf"
Response.CacheControl = "public"

Response.BinaryWrite varBuffer