会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
王翔 KingFly PHP
WEB开发者的技术乐园 千人技术群:306157454
首页
联系
管理
.NET上传单张图片代码
//
上传图片
protected
void
Button4_Click(
object
sender, EventArgs e)
{
Random rad
=
new
Random();
string
pathname
=
Server.MapPath(
"
img/
"
);
//
要保存到的文件夹
string
filename
=
FileUpload1.FileName;
//
选中的图片名
string
filepath
=
DateTime.Now.Millisecond
+
rad.Next().ToString()
+
filename;
//
要保存的图片名
int
filesize
=
FileUpload1.PostedFile.ContentLength;
//
图片大小
string
filetype
=
filename.Substring(filename.LastIndexOf(
"
.
"
)
+
1
);
//
图片后缀
if
((filetype
==
"
jpg
"
||
filetype
==
"
jpeg
"
||
filetype
==
"
gif
"
))
{
//
文件大小要小于200k
if
(filesize
<
200000
)
{
FileUpload1.PostedFile.SaveAs(Server.MapPath(
"
~/img/
"
)
+
filepath);
Image1.ImageUrl
=
"
~/img/
"
+
filepath;
//
用image控件显示一下图
TextBox7.Text
=
"
~/img/
"
+
filepath;
//
把图片地址保存到图片地址框中
}
else
{
TextBox7.Text
=
"
图片超过100K了!
"
;
}
}
else
{
TextBox7.Text
=
"
不能上传这种格式的图片!
"
;
}
TextBox8.Focus();
//
聚焦到下一个输入框
}
posted @
2009-09-23 17:15
王翔(kingfly)
阅读(
422
) 评论(
0
)
编辑
收藏
举报
刷新页面
返回顶部