protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.FileName; //获取已上传文件的名字
string size = FileUpload1.PostedFile.ContentLength.ToString(); //获取已上传文件夹的大小
string type = name.Substring(name.LastIndexOf(".") + 1); //得到文件的后缀
string ipath = Server.MapPath("up") + "\\" + name; //获取文件夹上传的实际路径
string fpath = Server.MapPath("upfile") + "\\" + name; //获取文件夹上传的实际路径
string wpath = "up\\" + name;
//下面我们得判断文件格式
if (type == "jpg" || type == "gif" || type == "bmp" || type == "png")
{
Image1.Visible = true;
FileUpload1.SaveAs(ipath); //将文件保存到path这个路径里面
Image1.ImageUrl = wpath; //让图片显示出来
Label1.Text = "你传的文件名称是:" + name + "<br>文件大小为:" + size + "字节<br>文件类型是:" + type + "<br>后缀名是:" + type + "<br>实际路径是:" + ipath + "<br>虚拟路径是:" + wpath;
}
else
{
Image1.Visible = false; //将图片控件隐藏,否则它会出现一个小XX
FileUpload1.SaveAs(fpath); //将文件夹保存在另一个文件夹
Label1.Text = "你传的文件名称是:" + name + "<br>文件大小为:" + size + "字节<br>文件类型是:" + type + "<br>后缀名是:" + type + "<br>实际路径是:" + ipath + "<br>虚拟路径是:" + wpath;
}
}
浙公网安备 33010602011771号