热心网友
回答时间:2024-10-27 02:55
if (this.ImgFileUp.PostedFile.ContentLength > 0)
{
string fullname = this.ImgFileUp.PostedFile.FileName.ToString();
string filename = fullname.Substring(fullname.LastIndexOf("\\") + 1);
filename = filename.Substring(0, filename.LastIndexOf("."));
string typ2 = fullname.Substring(fullname.LastIndexOf(".") + 1).ToLower();
string currentFileName = "";
if (typ2 == "gif" || typ2 == "jpg" || typ2 == "bmp" || typ2 == "png" || typ2 == "jpeg")
{
currentFileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "." + typ2;
string newbag = DateTime.Now.ToString("yyyyMMdd") ;
if (!System.IO.Directory.Exists(Server.MapPath("~\\upload_files\\images\\" + newbag)))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~\\upload_files\\images\\" + newbag));
}
this.ImgFileUp.SaveAs(Server.MapPath("~\\upload_files\\images\\" + newbag + "") + "\\" + currentFileName);
this.ImgUrl1.Value = "upload_files/images/" + newbag + "/" + currentFileName;
//Response.Write(this.ImgUrl1.Value);
}
else if (typ2 == "txt" || typ2 == "zip" || typ2 == "rar" || typ2 == "doc" || typ2 == "docx" || typ2 == "xls" || typ2 == "ppt" || typ2 == "pdf" || typ2 == "swf" || typ2 == "flv")
{
currentFileName = System.DateTime.Now.ToString("yyyyMMddHHmmss") + "." + typ2;
string newsfile = DateTime.Now.ToString("yyyyMMdd") ;
if (!System.IO.Directory.Exists(Server.MapPath("~\\upload_files\\files\\" + newsfile)))
{
System.IO.Directory.CreateDirectory(Server.MapPath("~\\upload_files\\files\\" + newsfile));
}
this.ImgFileUp.SaveAs(Server.MapPath("~\\upload_files\\files\\" + newsfile + "") + "\\" + currentFileName);
this.ImgUrl1.Value = "upload_files/files/" + newsfile + "/" + currentFileName;
//this.Page.ClientScript.RegisterClientScriptBlock(GetType(), "", "alert('"+this.ImgUrl1.Value+"');", true);
//Response.Write("<script language='javascript'>parent.Alert('图片必须gif,jpg,bmp或者png格式!');</script>");
//Response.End();
//return;
}
收起