No crap ExtJS Getting Started tutorial 14 [text Editor: Editor]extjs technology Exchange, welcome Dabigatran (201926085)
ExtJS's own editor does not have the ability to upload images, most of the time it can meet our needs.
But sometimes this functionality is still needed. I'm here to integrate the Keeditor.
The first thing to download is keeditor and the LitJson.dll to be referenced when uploading. Because Ke's version is different, the download file I provide here is only applicable to the current integration code for reference.
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/upload.ashx
1 using System; 2 using System.Collections.Generic; 3 using System.Collections; 4 using System.IO; 5 using System.Web; 6 using System.Globalization; 7 using Litjson; 8 9 namespace Hzyt. ExtJs.WebSite.App_Ashx10 {One-to-one//<summary>12//Upload//</SUMMARY>14 public class UPLOAD:IHTTPHANDLER15 {16//File save directory path Savepath = app_code.constant.uploadimagepath;1 8//File save directory URL19 private String saveurl = app_code.constant.uploadimagepath;20//define the file extension allowed to upload 21 Private String filetypes = "Gif,jpg,jpeg,png,bmp"; 22//Maximum file size: $ private int maxSize = 1000000;24 25 Private HttpContext context;26 public void ProcessRequest (HttpContext context) 28 {29 This.context = context;30 Httppostedfile imgfile = context. request.files["Imgfile"];32 if (imgfile = = null) @ showerror ("Please select File. "); 35 }36 PNS String Dirpath = context. Server.MapPath (Savepath); Directory.Exists (Dirpath)) (The upload directory does not exist.) ");}42-String fileName = imgfile.filename;44 String fileext = Path.getextension ( FileName). ToLower () ArrayList filetypelist = Arraylist.adapter (Filetypes.split (', ')), if (imgfile.in Putstream = = NULL | | ImgFile.InputStream.Length > MaxSize) (the upload file size exceeds the limit.) ");}51 if (String.IsNullOrEmpty (fileext) | | Array.indexof (Filetypes.split (', '), fileext.substring (1). ToLower ()) = =-1) @ showerror ("The Upload file extension is an extension that is not allowed. ");}56-String NewFileName = DateTime.Now.ToString (" Yyyymmddhhmmss_ffff ", DateTimeFormatInfo. Invariantinfo) + fileext;58 String FilePath = Dirpath + newfilename;59 imgfile.saveas (FilePath) ; 61 FileUrl String = saveurl + newfilename;63 Hashtable hash = new Hashtable (); ash["error"] = 0;66 hash["url"] = fileurl;67 context. Response.AddHeader ("Content-type", "text/html; Charset=utf-8 "); Response.Write (Jsonmapper.tojson (hash)); Response.End ();}71 private void ShowError (String message), Hashtable hash = New Hashtable (); hash["error"] = 1;76 hash["message"] = message;77 context. Response.AddHeader ("Content-type", "text/html; Charset=utf-8 "); Response.Write (Jsonmapper.tojson (hash)); Response.End (),}81, IsReusable83, get85 {86 return true;87}88}89}90}
2. The effect is as follows:
File Download:
Keeditor LitJson.dll
No crap ExtJS Getting Started tutorial 14 [Text Editor: editor]