您的位置:首页 >我爱生活 >

fileupload1 文件后缀名(fileupload1)

导读 大家好,我是小曜,我来为大家解答以上问题。fileupload1 文件后缀名,fileupload1很多人还不知道,现在让我们一起来看看吧!string path...

大家好,我是小曜,我来为大家解答以上问题。fileupload1 文件后缀名,fileupload1很多人还不知道,现在让我们一起来看看吧!

string path = "";

if (FileUpload1.HasFile)

{

//删除图片

if (File.Exists(Server.MapPath(_Article.ArticlePicture)))

{

try { Tool.DeleteFile(Server.MapPath(_Article.ArticlePicture)); }

catch { }

}

if (!FileHelper.IsImageType(FileUpload1.FileName))

{

MessageBox.Show(Page, string.Format("请上传 {0} 结尾的图片文件", FileHelper.ImageTypes));

return;

}

string XNpath = "/Upload/Article";

path = XNpath + "/" + FileUpload1.FileName;

if (!Directory.Exists(Server.MapPath(XNpath)))

Directory.CreateDirectory(Server.MapPath(XNpath));

FileUpload1.SaveAs(Server.MapPath(path));

}

public static bool IsImageType(string fileName)

{

bool isImage = false;

string extend = GetExtend(fileName);

switch (extend.ToLower())

{

case ".jpg": isImage = true; break;

case ".jpeg": isImage = true; break;

case ".gif": isImage = true; break;

case ".png": isImage = true; break;

default: isImage = false; break;

}

return isImage;

}

本文到此讲解完毕了,希望对大家有帮助。

免责声明:本文由用户上传,如有侵权请联系删除!