zoukankan
html css js c++ java
.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();
//
聚焦到下一个输入框
}
查看全文
相关阅读:
2010上交:计算表达式
添加子评论
上传图片
settings配置 文件操作
django 操作前端数据
静态文件配置
render httprequest
上传文件配置
Django为什么要跳转到不同的页面来实现不同的功能
定义日志器
原文地址:https://www.cnblogs.com/kingfly/p/1572780.html
最新文章
C语言中的字符串
C语言的函数
关键字
ZOJ- 3640 Help Me Escape
ZOJ Problem Set
495. Kids and Prizes
poj3071 Football
HDU-4974 A simple water problem
HDU-4972 A simple dynamic programming problem
HDU-4968 Improving the GPA
热门文章
HDU-4089 Activation
2011年浙大:Twin Prime Conjecture
2011上交:整除问题
VijosP1180:选课
VijosP1100:加分二叉树
Vijos1132:求二叉树的先序序列
VijosP1626:爱在心中
VijosP1595:学校网络(有向图变强连通图)
2010上交:后缀子串排序
2010上交:最短路径
Copyright © 2011-2022 走看看