zoukankan
html css js c++ java
上传图片代码。
前台是一个upload控件加一个按钮:
addline.aspx:
<
tr
>
<
td
style
=" 30px"
>
<
asp:Label
ID
="Label9"
runat
="server"
Text
="Picture URL:"
></
asp:Label
></
td
>
<
td
>
<
asp:TextBox
ID
="imgurl"
runat
="server"
>
../img/Noimg.jpg
</
asp:TextBox
>
<
asp:Label
ID
="addimg"
runat
="server"
ForeColor
="Red"
></
asp:Label
><
br
/>
<
asp:Label
ID
="Label10"
runat
="server"
Text
="Choose PIC:"
></
asp:Label
>
<
asp:FileUpload
ID
="imgurl1"
runat
="server"
/>
<
asp:Button
ID
="Button1"
runat
="server"
OnClick
="Button1_Click"
Text
="upload"
/></
td
>
</
tr
>
addline.cs:
protected
void
Button1_Click(
object
sender, EventArgs e)
{
Boolean fileOK
=
false
;
String path
=
Server.MapPath(
"
~/img/tour/
"
);
String url
=
"
../img/tour/
"
+
imgurl1.FileName;
if
(imgurl1.HasFile)
{
String fileExtension
=
System.IO.Path.GetExtension(imgurl1.FileName).ToLower();
String[] allowedExtensions
=
{
"
.gif
"
,
"
.png
"
,
"
.jpeg
"
,
"
.jpg
"
}
;
for
(
int
i
=
0
; i
<
allowedExtensions.Length; i
++
)
{
if
(fileExtension
==
allowedExtensions[i])
{
fileOK
=
true
;
}
}
}
if
(fileOK)
{
imgurl1.PostedFile.SaveAs(path
+
imgurl1.FileName);
addimg.Text
=
"
File uploaded!
"
;
imgurl.Text
=
url;
}
else
{
addimg.Text
=
"
Cannot accept files of this type.
"
;
}
}
查看全文
相关阅读:
同一个ip、不同端口的两个应用,cookie竟然是可以互相访问到
JS类型判断typeof、instanceof、Object.prototype.toString.call()
js 控制一次加载一张图片,加载完成后再加载下一张
cookie机制和session机制的区别
Do not access Object.prototype method 'hasOwnProperty' from target object
Vue 中使用mockjs模拟后端数据
vue遍历数据字典
this的用法
关于html5的离线缓存(转帖)
js正则 (二)
原文地址:https://www.cnblogs.com/ddr888/p/601174.html
最新文章
windows上git安装及基本配置
记:同一设备安装多数据库
openpyxl基础
jsonpath-rw使用
charles 结合移动端APP 配置及协议抓包
requests '上传文件'操作方法
通过结合ddt的方法去加载运行excel当中的用例数据并生成报告
py开源方法 Faker(随机生成数据)
小程序--记录一些小问题
微信小程序开发
热门文章
javascript里的循环语句
百度API地图的标注不居中显示,而显示在左上角
深入解读 Js 中的面向对象编程
Vue常用开源项目汇总
MIP (百度移动网页加速器)
判断鼠标向上滚动或者向上滚动触发不同的事件
在JavaScript里 (a ==1 && a== 2 && a==3) 有可能是 true 吗?
Ajax与服务器(JSON)通信介绍
el-upload上传图片方法
css实现自适应的圆
Copyright © 2011-2022 走看看