选择显示字体大小

在asp.net中保存/取出图片入/从sql数据库(可用于上传图片)

一、把图片存入数据库
 
用到以下几个方面的知识:
1. 使用流对象
2. 查找准备上传的图片的大小和类型
3.怎么使用inputstream方法

插入图片的必要条件
1.#form 标记的 enctype 属性应该设置成 enctype="multipart/form-data"
2.# 需要一个<input type=file>表单来使用户选择他们要上传的文件,同时我们需要导入 system.io名称空间来处理流对象
sqlserver做以下的准备
1.# 需要至少含有一个图片类型的字段的表
2.# 如果我们还有另外一个变字符类型的字段来存储图片类型,那样会更好一些。

窗体控件
1.插入图片用到的是system.web.ui.htmlcontrols.htmlinputfile控件,我们在webform中放入这个控件,取名为“imginput”
2.同时再放入一个确认上传按钮“button1”

程序代码
addimg,用于返回要上传的图片内容

 1private function addimg()function addimg(byval inputimg as system.web.ui.htmlcontrols.htmlinputfile, byval imgtype as string, byval maxsize as int64) as byte()
 2'传入一个htmlinputfile控件,一个上传图片格式和一个上传图片最大值,返回图片的内容,既要写入数据库中的内容,你也可以同时写入图片类型
 3        dim intimagesize as int64
 4        dim strimagetype as string
 5        dim imagestream as stream
 6        ' gets the image type
 7   strimagetype=inputimg.postedfile.contenttype
 8        if strimagetype <> imgtype then
 9            response.write("<script>alert('图片类型为""')</script>") 'jgp类型为"image/pjpeg"
10            exit function
11        end if
12        ' gets the size of the image
13        intimagesize = inputimg.postedfile.contentlength
14        if intimagesize > maxsize then
15            response.write("<script>alert('图片不得大于k')</script>")
16            exit function
17        end if
18        ' reads the image
19        imagestream = inputimg.postedfile.inputstream
20        dim imagecontent(intimagesize) as byte
21        dim intstatus as integer
22        intstatus = imagestream.read(imagecontent, 0, intimagesize)
23        return imagecontent
24    end function
示例调用

dim imagecontent() as byte
       imagecontent = addimg(fileimg, "image/pjpeg", 512000)'上传图片类型为jpg,最大不超过500k

插入数据库

我想这部分就不用写了吧,你可以用任何方式(推荐使用存储过程),将imagecontent插入到数据库中类型为image的字段就行了。


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons