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.
"
;
}
}
查看全文
相关阅读:
alpha冲刺—Day5
alpha冲刺—Day4
alpha冲刺—Day3
alpha冲刺—Day2
alpha冲刺—Day1
团队作业第五次—alpha冲刺博客汇总
团队作业第四次—项目系统设计与数据库设计
团队作业第三次—项目需求分析
团队作业第二次—团队Github实战训练
win10配置java环境变量,解决javac不是内部或外部命令等问题
原文地址:https://www.cnblogs.com/ddr888/p/601174.html
最新文章
RATE-MAX alpha冲刺第七天
RATE-MAX alpha冲刺第六天
RATE-MAX alpha冲刺第五天
RATE-MAX alpha冲刺第四天
RATE-MAX alpha冲刺第三天
代码规范+任务规划
RATE-MAX alpha冲刺第二天
RATE-MAX alpha冲刺第一天
Alpha冲刺——博客汇总
Alpha冲刺——代码规范和冲刺计划
热门文章
Alpha冲刺——第六天
Alpha冲刺——第五天
Alpha冲刺——第四天
Alpha冲刺——第三天
Alpha冲刺——第二天
Alpha冲刺——第一天
D6 Plus——站立式会议+alpha冲刺
D6 Plus——项目系统设计与数据库设计
D6 Plus——项目需求分析
alpha冲刺—Day6
Copyright © 2011-2022 走看看