当前位置:首页 > ASP教程 > 应用技巧

ASP实现强制图片下载函数

图片不进行处理,图片默认是用浏览器打开显示,如果希望图片变为下载可以使用以下代码

function downloadfile(strfile)
    strfilename = server.mappath(strfile)
 
    response.buffer = true
    response.clear
 
    set s = server.createobject("adodb.stream")
    s.open
 
    s.type = 1
 
    on error resume next
 
    set fso = server.createobject("scripting.filesystemobject")
    if not fso.fileexists(strfilename) then
        response.write("<h1>error:</h1>" & strfilename & " does not exist<p>")
        response.end
    end if
 
    set f = fso.getfile(strfilename)
    intfilelength = f.size
 
    s.loadfromfile(strfilename)
    if err then
        response.write("<h1>error: </h1>" & err.description & "<p>")
        response.end
    end if
 
    response.addheader "content-disposition", "attachment; filename=" & f.name
    response.addheader "content-length", intfilelength
    response.charset = "utf-8"
    response.contenttype = "application/octet-stream"
 
    response.binarywrite s.read
    response.flush
 
    s.close
    set s = nothing
end function

以上所述就是本文给大家分享的函数了,希望对大家学习asp能够有所帮助。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!