</script> ============================================================================= Using System; Using System.Collections.Generic; Using System.IO; Using System.Linq; Using System.Web; Using System.Web.SessionState; Using UI; Namespace Admin.TkAdmin.Product { <summary> Summary description of Imgsave </summary> public class Imgsave:ihttphandler,ireadonlysessionstate { Public HttpRequest Request; Public HttpResponse Response; Public HttpSessionState Session; public void ProcessRequest (HttpContext context) {
Context. Response.ContentType = "Text/plain"; Response = context. Response; Request = context. Request; Session = context. Session; String upfile = request["Upfile"]; if (upfile! = "") { If the value is 1zhi if (Upfile = = "1") { UploadFile (); } }
} Save the uploaded image to the specified file private void UploadFile () { Httppostedfile file = request.files["Filedata"]; String uploadfile = ""; HttpContext.Current.Server.MapPath (@Request ["folder"]); String newfilename = ""; if (file! = null) { Isfile (UploadFile); try { Create Random Seed Random RA; if (session["intindeximg"]! = NULL) { RA = new Random (Convert.ToInt32 (session["intindeximg")); } Else { RA = new Random (); } int rInt = ra. Next (1000); session["intindeximg"] = rInt; NewFileName = DateTime.Now.ToString ("YYYYMMDDHHMMSS") + "_" + rInt + path.getextension (file. FileName). ToUpper (); String Bigimageurl = (Fileurl.productbigimgurl + newfilename). Replace (' \ \ ', '/'); Isfile (Fileurl.productbigimgurl); File. SaveAs (Bigimageurl); Save the Indent graph String Smallimgeurl = (Fileurl.productsmallimgurl + newfilename). Replace (' \ \ ', '/'); Isfile (Fileurl.productsmallimgurl); Createsmallpic.createimageoutput (Bigimageurl, Smallimgeurl); Response.Write ("1|@|" + FILEURL.PRODUCTSMALLIMGURL1 + newfilename); }catch { Response.Write ("0"); } } } Used to create a directory private void Isfile (String uploadfile) { if (! Directory.Exists (UploadFile)) { Directory.CreateDirectory (UploadFile); } } public bool IsReusable { Get { return false; } } } } |