enctype="multipart/form-data" 改变请求报文的报文格式
if (context.Request.Files.Count > 0)
{
HttpPostedFile file = context.Request.Files[0];
if (file.ContentLength > 0)
{
//string filename = System.IO.Path.GetFileName(file.FileName);
//string path = context.Request.MapPath("upload/" + filename);
if (file.ContentType == "image/jpeg")
{
string ext = System.IO.Path.GetExtension(file.FileName);
//唯一的文件名
Random random = new Random();
string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(1000, 10000) + ext;
string path = context.Request.MapPath("upload/" + filename);
file.SaveAs(path);
}
else
{
context.Response.Write("shou jian");
}
}
else
{
context.Response.Write("请选择文件");
}
}