protected void Button1_Click(object sender, EventArgs e)
{
bool fileok = false;
string filename = InputFile.FileName;
//string fileExtension = System.IO.Path.GetExtension(filename);
//string path = Server.MapPath("~/upload/");
if (InputFile.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(InputFile.FileName).ToLower();
string[] allowedExtensions = { ".gif", ".bmp", ".png", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileok = true;
}
}
}
//图片上传
if (fileok)
{
string uploadName = InputFile.PostedFile.FileName;//获取待上传图片的完整路径,包括文件名
string serverpath = Server.MapPath("~/upload/blocklogo/") + filename;//取得文件在服务器上保存的位置
InputFile.PostedFile.SaveAs(serverpath);
string imgurl = "upload/blocklogo/" + filename;
Session["imgurl"] = imgurl;
Label2.Text = "上传成功!" + "你上传的文件名:" + filename + ";文件大小为:" + InputFile.PostedFile.ContentLength+"B" ;
//Label2.Text = serverpath;
// FreeTextBox1.Text = "<img src='" + serverpath + "'>";
}
else
{
Label3.Text = "上传文件类型:.gif,.bmp.png.jpg";
}
}
{
bool fileok = false;
string filename = InputFile.FileName;
//string fileExtension = System.IO.Path.GetExtension(filename);
//string path = Server.MapPath("~/upload/");
if (InputFile.HasFile)
{
string fileExtension = System.IO.Path.GetExtension(InputFile.FileName).ToLower();
string[] allowedExtensions = { ".gif", ".bmp", ".png", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileok = true;
}
}
}
//图片上传
if (fileok)
{
string uploadName = InputFile.PostedFile.FileName;//获取待上传图片的完整路径,包括文件名
string serverpath = Server.MapPath("~/upload/blocklogo/") + filename;//取得文件在服务器上保存的位置
InputFile.PostedFile.SaveAs(serverpath);
string imgurl = "upload/blocklogo/" + filename;
Session["imgurl"] = imgurl;
Label2.Text = "上传成功!" + "你上传的文件名:" + filename + ";文件大小为:" + InputFile.PostedFile.ContentLength+"B" ;
//Label2.Text = serverpath;
// FreeTextBox1.Text = "<img src='" + serverpath + "'>";
}
else
{
Label3.Text = "上传文件类型:.gif,.bmp.png.jpg";
}
}