No crap ExtJS Getting Started tutorial 13 [Upload Image: File]extjs technology exchange, welcome Dabigatran (201926085)
1. The code is as follows:
1 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> 2 Where the service interacts with the upload image of the general processing program file, the source code is as follows:
/app_ashx/demo/upload.ashx
1 using System; 2 using System.Web; 3 using System.IO; 4 using System.Globalization; 5 6 namespace Hzyt. ExtJs.WebSite.App_Ashx.Demo 7 {8 public class Upload:ihttphandler 9 {ten public void ProcessRequest (Http Context context) 11 {12//virtual directory, recommended to write in configuration file, String strpath = "/upload/image/"; 14 File local directory, String Dirpath = context. Server.MapPath (strpath); 16//Receive file Httppostedfile Imgfile = context. request.files["Imgfile"];18//Remove the file extension, String Fileext = Path.getextension (imgfile.filename). ToLower (); 20//Rename the file by String NewFileName = DateTime.Now.ToString ("Yyyymmddhhmmss_ffff", DateTime Formatinfo.invariantinfo) + fileext;22//File Upload path @ String filePath = dirpath + newfilename;24 Save File Imgfile.saveas (FilePath); 26//client output in the context. Response.Write ("{success:true,path: '" + strpath + NewFileName + "'}");}29-public bool IsReusable31 {get33 {34 return false;35}36}37}38}
2. The effect is as follows:
3. Description:
(1) Upload a domain not only to upload pictures, but also to upload other files. Here we take the picture as an example.
(2) in the actual development, we also have to check the image format, size, and so on, this example weighs on the upload, did not add any verification.
No crap ExtJS Getting Started tutorial 13 [upload Image: File]