<%@ WebHandler Language="C#" Class="upload" %>
using System;
using System.Web;
using System.IO;
public class upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
HttpPostedFile file = context.Request.Files[0];
if (file.ContentLength > 0)
{
string contenttype = file.ContentType;
if (contenttype == "image/jpeg")
{
Random random = new Random();
string ext = System.IO.Path.GetExtension(file.FileName);
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(10000, 100000) + ext;
string path = context.Request.MapPath("upload/" + fileName);
//保存文件
file.SaveAs(path);
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
using System;
using System.Web;
using System.IO;
public class upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
HttpPostedFile file = context.Request.Files[0];
if (file.ContentLength > 0)
{
string contenttype = file.ContentType;
if (contenttype == "image/jpeg")
{
Random random = new Random();
string ext = System.IO.Path.GetExtension(file.FileName);
string fileName = DateTime.Now.ToString("yyyyMMddhhmmss") + random.Next(10000, 100000) + ext;
string path = context.Request.MapPath("upload/" + fileName);
//保存文件
file.SaveAs(path);
}
}
}
public bool IsReusable {
get {
return false;
}
}
}
4478

被折叠的 条评论
为什么被折叠?



