大家好:
想請問用asp下載word會產生亂碼..pdf或用zip打包則不會,想問有甚麼方法
謝謝
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
fName="porojecpaper.doc"
sDir= "./pap/" & fName
tDir= "./Down/" & fName
sourceDir=Server.MapPath(sDir)
backupDir=Server.MapPath(tDir)
fs.CopyFile sourceDir,backupDir
if fs.FileExists(backupDir) then
Const adTypeBinary = 1
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Charset = "utf-8"
objStream.Type = adTypeBinary
objStream.LoadFromFile backupDir
Response.AddHeader "Content-Disposition", "attachment; filename=" & fName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "utf-8"
Response.ContentType = "application/msword"
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
fs.DeleteFile backupDir,True
else
response.write "檔案不存在,請洽承辦人"
end if
%>
給他轉址下載@@..
<%
Set fs=Server.CreateObject("Scripting.FileSystemObject")
fName="porojecpaper.doc"
sDir= "./pap/" & fName
sourceDir=Server.MapPath(sDir)
if fs.FileExists(sourceDir) then
Response.Redirect sDir
else
response.write "檔案不存在,請洽承辦人"
end if
%>
可以下載,不過複製過的檔案無法刪除@@
恩??可是你原先是@@~原始檔案複製→再把複製檔案下載@@...
我改這樣是直接下載原始檔案了@@~所以沒刪除~
謝謝
剛找到資料先把原本的資料夾中的檔案刪除再copy
function delfile(dDir)
Set fs=Server.CreateObject("Scripting.FileSystemObject")
backupDir=Server.MapPath(dDir)
Set objFolder = fs.GetFolder(backupDir)
Set objFiles = objFolder.Files
dim curFile
For each curFile in objFiles
fs.DeleteFile(curFile)
Next
end function
Response.Clear
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & SaveName
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End