【问题标题】:File fetch from database using asp使用asp从数据库中获取文件
【发布时间】:2012-02-13 09:04:04
【问题描述】:

我正在数据库中存储一些文件的一些二进制数据(是的,我知道这可能是个坏主意)。我能够以正确的内容类型取出文件,因为我已经存储了它。但是我无法使用正确的文件名将文件发送给客户端。现在我在一个名为 get_file.asp 的文件中有以下代码:

sSQL = "SELECT filename, contenttype, binarydata FROM new_attachment WHERE filename = '" & filename & "'"

oRs.Open sSQL, conn, 3, 3

If Not oRs.EOF Then
    Response.ContentType = oRs(1)
    Response.BinaryWrite oRs(2)

End if

这将正确返回文件,但文件名为“get_file.asp”,而不是“myfile.txt”。访问的网址是.../get_file.asp?filename=myfile.txt

当浏览器提示用户将文件保存在某处时,我是否可以更改文件名?

【问题讨论】:

标签: asp-classic download content-type


【解决方案1】:

您需要添加一个Content-Disposition 标头。

标题应如下所示:

Content-Disposition: attachment; filename=<name of file>

旁注:您连接 SQL 的方式对SQL Injection 开放 - 您应该使用参数。

【讨论】:

    【解决方案2】:

    您需要发送正确的标头:

    Response.ContentType = "text/html"
    Response.AddHeader "Content-Disposition", "attachment; filename=YOURFILE.TXT"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-16
      • 2014-05-06
      • 2013-04-11
      • 1970-01-01
      • 2016-04-01
      • 2014-12-11
      • 1970-01-01
      • 2012-02-29
      相关资源
      最近更新 更多