private string UploadFile(FileUpload fileup)
{
string FileName = "";
string filetype = "";
if (fileup.HasFile == true)
{
//判断类型是否符合要求
filetype = System.IO.Path.GetExtension(fileup.FileName).ToUpper();
if (filetype == ".JPEG" || filetype == ".JPG" || filetype == ".BMP" || filetype == ".GIF" || filetype == ".PNG")
{
//判断文件大小
if (fileup.PostedFile.ContentLength > 1048576)
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传文件不能超过1M?)</script>");
FileName = "";
}
else
{
try
{
FileName = DateTime.Now.Ticks + "_" + fileup.FileName;
fileup.SaveAs(Server.MapPath("/images/") + FileName);
}
catch
{
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('上传文件失败?)</script>");
FileName = "";
}
}
}
}
return FileName;
}
上传文件判断并返回名称(插入数据时可用)
最新推荐文章于 2024-04-09 18:56:38 发布