fileupload 上传问题 上传图片或文件的时候提示路径
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Web;usingSys...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace luanqibazao
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;//获取上传文件名
string size = FileUpload1.PostedFile.ContentLength.ToString();//获取上传文件大小
string type = FileUpload1.PostedFile.ContentType;//获取类型
string type2 = name.Substring(name.LastIndexOf(".") + 1);//获取后缀
string ipath = Server.MapPath("upimg") + "//" + name;
string fpath=Server.MapPath("upfile")+"//"+name;
string wpath = "upimg//" + name;//写入虚拟路径
if (type2 == "jpg" || type2 == "jif" ||type2 == "bmp" || type2 == "png")
{
FileUpload1.SaveAs(ipath);//将文件保存到path
Image1.ImageUrl = wpath;//显示图片
Label1.Text = "文件名" + name + "<br>文件大小是" + size + "字节<br>文件类型是" + type;
}
else
{
Image1.Visible = false;//图片控件隐藏
FileUpload1.SaveAs(fpath);
Label1.Text = "文件名" + name + "<br>文件大小是" + size + "字节<br>文件类型是" + type;
}
}
}
} 展开
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
namespace luanqibazao
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName;//获取上传文件名
string size = FileUpload1.PostedFile.ContentLength.ToString();//获取上传文件大小
string type = FileUpload1.PostedFile.ContentType;//获取类型
string type2 = name.Substring(name.LastIndexOf(".") + 1);//获取后缀
string ipath = Server.MapPath("upimg") + "//" + name;
string fpath=Server.MapPath("upfile")+"//"+name;
string wpath = "upimg//" + name;//写入虚拟路径
if (type2 == "jpg" || type2 == "jif" ||type2 == "bmp" || type2 == "png")
{
FileUpload1.SaveAs(ipath);//将文件保存到path
Image1.ImageUrl = wpath;//显示图片
Label1.Text = "文件名" + name + "<br>文件大小是" + size + "字节<br>文件类型是" + type;
}
else
{
Image1.Visible = false;//图片控件隐藏
FileUpload1.SaveAs(fpath);
Label1.Text = "文件名" + name + "<br>文件大小是" + size + "字节<br>文件类型是" + type;
}
}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询