>>>>上传二进制文件(比如word文档)到数据库后,如何从数据库中读取<<<<<

sq0421 2003-10-21 02:51:35
我通过上传图片文件到数据库的方法,可以把其他类型的文件也存到数据库image字段中,但采用原来的读图片的方法来读这样的数据

Response.ContentType = "image/*"
Response.BinaryWrite rs("file_content")

也能读,但文件类型就不对了,保存到硬盘上的文件扩展名为.asp
如何解决?????????????
...全文
20 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
sq0421 2003-10-22
多谢二位,我是考虑到用文件的形式会被下载,用数据库的方式就比较安全。
回复
gasover 2003-10-21
更正, 如果要下载的话,请把上面这句:Response.AddHeader "Content-Disposition", "filename=" &
改成:
Response.AddHeader "Content-Disposition", "attachment; filename=" &

回复
heguowei 2003-10-21
用文件的方法多好,只存储文件的路径即可
回复
gasover 2003-10-21
<%

Response.Buffer = true

Response.Clear



……

……



url=rs("url") '数据库操作,读出文件路径,存到变量url中





Set fso=Server.CreateObject("Scripting.FileSystemObject")

Set fl=fso.getfile(url)

flsize=fl.size

flName=fl.name

Set fl=Nothing

Set fso=Nothing

%>

<%

Set objStream = Server.CreateObject("ADODB.Stream")

objStream.Open

objStream.Type = 1

objStream.LoadFromFile url





Select Case lcase(Right(flName, 4))

Case ".asf"

ContentType = "video/x-ms-asf"

Case ".avi"

ContentType = "video/avi"

Case ".doc"

ContentType = "application/msword"

Case ".zip"

ContentType = "application/zip"

Case ".xls"

ContentType = "application/vnd.ms-excel"

Case ".gif"

ContentType = "image/gif"

Case ".jpg", "jpeg"

ContentType = "image/jpeg"

Case ".wav"

ContentType = "audio/wav"

Case ".mp3"

ContentType = "audio/mpeg3"

Case ".mpg", "mpeg"

ContentType = "video/mpeg"

Case ".rtf"

ContentType = "application/rtf"

Case ".htm", "html"

ContentType = "text/html"

Case ".txt"

ContentType = "text/plain"

Case Else

ContentType = "application/octet-stream"

End Select







Response.AddHeader "Content-Disposition", "filename=" &



flName

Response.AddHeader "Content-Length", flsize



Response.Charset = "UTF-8"

Response.ContentType = ContentType



Response.BinaryWrite objStream.Read

Response.Flush

response.Clear()

objStream.Close

Set objStream = Nothing



%>

回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2003-10-21 02:51
社区公告
暂无公告