-1
我需要從服務器上的文件夾下載文件。下載asp classic上的DWG文件
我已經嘗試過ASP代碼中的這段代碼,但是當文件是DWG時,下載不起作用。
我沒有錯誤,下載所有文件類型的代碼都是DWG文件。
任何人都可以幫助我嗎?
在此先感謝。
我的代碼如下。
getfile.asp
<%
Function BaseName(byVal Path)
Dim Pos
Path = Replace(Path,"/","\")
Pos = InStrRev(Path,"\")
If Pos>0 then
BaseName = Mid(Path,Pos+1)
Else
BaseName = Path
End if
end function
Function ReadFile(FileName)
Dim Stream , Path
On error resume next
Path = Server.MapPath(FileName)
If Err.Number<>0 then Path = FileName
On error goto 0
Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Type=1
Stream.Open()
Stream.LoadFromFile Path
Stream.Position=0
ReadFile = Stream.Read()
Stream.Close()
Set Stream = Nothing
End Function
' Timeout
Server.ScriptTimeout=6000
if Len(Trim(request.querystring("file"))) > 0 then
file = server.mappath(request.querystring("file"))
else
Response.Write("file not found")
Response.end
end if
response.ContentType="application/octet-stream"
response.AddHeader "Content-Disposition", "attachment; filename=" & BaseName(file)
Response.BinaryWrite ReadFile(File)
Response.End
%>
的default.asp
<script language="JavaScript" type="text/javascript">
function doDownload(file1, file2, frmName)
{
var ifrmObj = document.getElementById((frmName && frmName.length > 0) ? frmName : "dwnFrm1");
ifrmObj.src = "";
ifrmObj.src = "getFile.asp?file=" + file1;
if (!file2 || file2.length <= 0) return;
// Timeout
window.setTimeout("doDownload('" + file2 + "', '', 'dwnFrm2');", 3000);
}
</script>
<body bgcolor="#EAEFFF">
<iframe id="dwnFrm1" style="display: none;"></iframe>
<iframe id="dwnFrm2" style="display: none;"></iframe>
extDWG = right(directoryfile.Name, 3)
if extDWG = "dwg" then
response.write ("<a href=""javascript:void(0);"" onclick=""doDownload('/MyFolder/" & Server.HTMLencode(folder) & "/"& Server.HTMLencode(directoryfile.Name) &"', '/MyFolder/" & Server.HTMLencode(folder) & "/X-cart.dwg');"">")
else
response.write ("<a href=""/MyFolder/" & folder & "/" & directoryfile.Name &""">")
end if