zoukankan
html css js c++ java
图片image和byte处理,fileupload上传图片 Virus
--
这是通过浏览某图片,把他存放到数据库中
string
filename
=
txt_filename.Text;
string
filecomment
=
txt_filecomment.Text;
string
SlaveFileName
=
FileUpload1.PostedFile.FileName;
byte
[] FileContent_img
=
null
;
DateTime UploadTime
=
DateTime.Now.Date;
string
id
=
lbl_id.Text;
RemoteRule remoteRule
=
(RemoteRule)GetRemoteingObjectByType(
typeof
(RemoteRule),
"
remoterule
"
);
DataSet ds
=
new
DataSet();
if
(id
==
""
)
{
ds
=
remoteRule.GetRuleByID(
-
1
);
DataRow dr
=
ds.Tables[
0
].NewRow();
if
(SlaveFileName
!=
""
)
{
//
读取所上传的文件的二进制流
HttpPostedFile file1
=
FileUpload1.PostedFile;
int
filelength
=
Convert.ToInt32(file1.InputStream.Length);
FileContent_img
=
new
byte
[filelength];
file1.InputStream.Read(FileContent_img,
0
, filelength);
//
这里所说的二进制流表现为什么样
}
else
{
SlaveFileName
=
null
;
}
dr[
"
FileName_ch
"
]
=
filename;
dr[
"
FileDesc_ch
"
]
=
filecomment;
dr[
"
SlaveFileName_ch
"
]
=
SlaveFileName;
dr[
"
FileContent_img
"
]
=
FileContent_img;
dr[
"
UploadUser_ch
"
]
=
this
.SystemModuleSettings.UserManage.CurrUserInfo[
"
RealName
"
].ToString();
dr[
"
UploadTime_dt
"
]
=
UploadTime;
ds.Tables[
0
].Rows.Add(dr);
string
result
=
remoteRule.InsRule(ds);
if
(result
==
""
)
{
Response.Write(
"
<script>alert('插入不成功') </script>
"
);
}
else
{
if
(result
!=
"
f
"
)
{
Response.Write(
"
<script>alert('插入成功') </script>
"
);
ViewState[
"
PageState
"
]
=
"
edit
"
;
lbl_id.Text
=
result.Substring(result.IndexOf(
"
,
"
)
+
1
);
setControlsValue();
}
else
{
Response.Write(
"
<script>alert('插入不成功') </script>
"
);
}
}
}
--
显示图片的
byte
[] Image_img
=
(
byte
[])ds_image.Tables[
0
].Rows[
0
][
"
Image_im
"
];
if
(Image_img.Length
==
0
)
return
;
int
filelength
=
Image_img.Length;
string
imageName
=
ds_image.Tables[
0
].Rows[
0
][
1
].ToString()
+
"
1
"
+
"
.jpg
"
;
string
myUrl
=
HttpContext.Current.Server.MapPath(
this
.Request.ApplicationPath)
+
@"
\TempDownLoad\
"
+
imageName;
FileStream fs
=
new
FileStream(myUrl, FileMode.OpenOrCreate);
BinaryWriter w
=
new
BinaryWriter(fs);
w.BaseStream.Write(Image_img,
0
, filelength);
w.Flush();
w.Close();
Image1.ImageUrl
=
Context.Request.ApplicationPath
+
"
/TempDownLoad/
"
+
imageName;
Bitmap bitmap
=
new
Bitmap(myUrl);
Image1.Width
=
bitmap.Width;
Image1.Height
=
bitmap.Height;
【Blog】
http://virusswb.cnblogs.com/
【MSN】
jorden008@hotmail.com
【说明】转载请标明出处,谢谢
反馈文章质量,你可以通过快速通道评论:
查看全文
相关阅读:
GitHub超详细图文攻略
HTML5本地存储——IndexedDB二:索引
HTML5 indexedDb 数据库
js 对象 浅拷贝 和 深拷贝
《黑客大曝光》实践部分——sql注入(7/8)
Linux内核设计第五周——扒开系统调用三层皮(下)
读书笔记——《黑客大曝光》(6/8)
《linux内核设计与实现》读书笔记第五章——系统调用
Linux内核设计第四周——扒开系统调用三层皮
《linux内核设计与实现》读书笔记第一、二章
原文地址:https://www.cnblogs.com/virusswb/p/1205030.html
最新文章
java接收图片的两种方法
java数据类型之间的转换
判断map集合中是否存在某个key
java获取当前时间的小时
Vue父子组件相互通讯方法总结
Vue如何使用mapGetters
Flink 源码解析 —— Flink JobManager 有什么作用?
Flink 源码解析 —— 如何获取 JobGraph?
Flink 源码解析 —— 深度解析 Flink 是如何管理好内存的?
Flink 源码解析 —— 如何获取 ExecutionGraph ?
热门文章
Flink 源码解析 —— 源码编译运行
你公司到底需不需要引入实时计算引擎?
Flink 从0到1学习 —— Flink 中如何管理配置?
Apache Flink 1.9 重大特性提前解读
Git的一些用法(下)
git 用法
css3 -webkit-filter
Git的一些用法
Windows7下安装MongoDB
html头文件设置常用之<meta>设置缓存
Copyright © 2011-2022 走看看