请教ASP高手解释一下这些代码!!

来源:百度知道 编辑:UC知道 时间:2024/07/01 01:07:56
这个是上传图片的显示代码
<%
set rs=server.createobject("ADODB.recordset")
sql="select * from imgurl where id="&trim(request("id"))
rs.open sql,conn,1,1
Response.ContentType="image/*"
Response.BinaryWrite rs("img").getChunk(8000000)
rs.close
set rs=nothing
set conn=nothing
%>
中的
Response.ContentType="image/*"
Response.BinaryWrite rs("img").getChunk(8000000)
这两句是什么意思呀?请帮我解释一下
能具体一点吗?ContentType="image/*"
getChunk(8000000) 这个什么意思,有什么用

<%
set rs=server.createobject("ADODB.recordset")
'建立ADO对象
sql="select * from imgurl where id="&trim(request("id"))
'负值T-SQL语句
rs.open sql,conn,1,1
'打开ADO对象并执行T-SQL语句
Response.ContentType="image/*"
'输出网页内容为Image格式
Response.BinaryWrite rs("img").getChunk(8000000)
'输出ADO对象中"Img"列里的值并利用ADO getchunk方法读取二进制数据
rs.close
'关闭对象
set rs=nothing
'清空对象
set conn=nothing
'清空连接
%>

你的代码的意思是:
你将你的图片上传到你的数据库中,如果你使用的数据库是mysql里,那你表单里肯定有img字段,这字段里就是存的是你图片的二进制代码。
而你以上的的代码是将你request("id")的图片显示出来,其中显示的时候通过转换二进制代码显示图片。

ContentType
ContentType 属性指定响应的 HTTP 内容类型。如果未指定 ContentType,默认为 text/HTML。

语法
Response.ContentType [= ContentType ]

参数
ContentType
描述内容类型的字符串。该字符串通常被格式化为类型/子类型,其中类型是常规内容范畴而子类为特定内容类型。有关支持内容类型的完整列表,请参阅 Web 浏览器文档或当前的 HTTP 规格说明。
示例