public
void
ProcessRequest(HttpContext context)
{
context.Response.ContentType =
"application/json"
;
HttpPostedFile _upfile = context.Request.Files[
"File"
];
if
(_upfile.ContentLength < 500000)
{
if
(
string
.IsNullOrEmpty(_upfile.FileName))
{
context.Response.Write(
"请上传图片"
);
}
string
fileFullname = _upfile.FileName;
string
dataName = DateTime.Now.ToString(
"yyyyMMddhhmmss"
);
string
fileName = fileFullname.Substring(fileFullname.LastIndexOf(
"\\"
) 1);
string
type = fileFullname.Substring(fileFullname.LastIndexOf(
"."
) 1);
if
(type ==
"bmp"
|| type ==
"jpg"
|| type ==
"gif"
|| type ==
"JPG"
|| type ==
"BMP"
|| type ==
"GIF"
)
{
_upfile.SaveAs(HttpContext.Current.Server.MapPath(
"photo"
)
"\\"
dataName
"."
type);
HttpCookie cookie =
new
HttpCookie(
"photo"
);
context.Response.Write(
"上传成功"
);
}
else
{
context.Response.Write(
"支持格式:|jpg|gif|bmp|"
);
}
}
else
{
context.Response.Write(
"你的图片已经超过500K的大小!"
);
}
}