荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: baty (新一代懒人), 信区: Database
标  题: 本文介绍如何将图片从SQL SERVER里读出来!
发信站: BBS 荔园晨风站 (Mon Oct 30 12:41:35 2000), 转信

请问sql server中如何存jpg或gif图片?
※用ADO Field对象的AppendChunk方法
 如何定义sql server 的字段类型,使之能存放多媒体
※将字段定义成IMAGE类型,用二进制存取即可
MS 的说法:

The following example constructs an HTTP header for an image and then
uses
the binary information from an image field in SQL Server to provide a
GIF to
 the browser.
   FILE: SHOWIMG.ASP
   <%@ LANGUAGE="VBSCRIPT" %>
   <%
   ' Clear out the existing HTTP header information
   Response.Expires = 0
   Response.Buffer = TRUE
   Response.Clear
   ' Change the HTTP header to reflect that an image is being passed.
   Response.ContentType = "image/gif"
   Set cn = Server.CreateObject("ADODB.Connection")
   Set cn = Server.CreateObject("ADODB.Connection")
   ' The following open line assumes you have set up a System
DataSource
   ' by the name of myDSN.
   cn.Open "DSN=myDSN;UID=sa;PWD=;DATABASE=pubs"
   Set rs = cn.Execute("SELECT logo FROM pub_info WHERE
pub_id='0736'")
   Response.BinaryWrite rs("logo")
   Response.End
   %>
This script only displays an image on the screen. If you wish to display
 an image from an HTML or ASP document you must refer to this script in
an image tag. For example, if you wished to display this image with a caption
describing it, you might use the following HTML page:
   <HTML>
   <HEAD><TITLE>Display Image</TITLE></HEAD>
   <BODY>
   This page will display the image New Moon Books from a SQL Server 6.5
   image field.<BR>
   <IMG SRC="SHOWIMG.ASP">
   </BODY>
   </HTML>
NOTE: The ASP script assumes that the image field (BLOB Data) in the SQL
Server table contains a raw GIF image. Internet browsers assume that raw
GIF or JPEG data follow the HTTP header. If any extraneous information is
containe JPEG data follow the HTTP header. If any extraneous information is
contained in the BLOB data, this will be passed by this script, and the image
will not display properly. This becomes important when you realize that most
methods of placing images into BLOB fields place extra information in the
form ofheaders with the image. Examples of this are Microsoft Access and
Microsoft Visual FoxPro. Both of these applications save OLE headers in the
BLOB field along with the actual binary data.
   This technique can also be applied to other types of binary data, not
just graphics. The browser needs to know what type of content is being
presented.
   Do this by specifying the proper mime type in the Response.ContentType
variable. For example, if you wanted to view a word document, you would set
the ContentType = "application/msword".

--
      我是懒人我怕谁!!

             我总有一种想为你而死的冲动

                          因为我不知如何才能把你打动

※ 来源:·BBS 荔园晨风站 bbs.szu.edu.cn·[FROM: 192.168.18.238]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店