FCKeditor controls in JSP-file type and size control __jsp

Source: Internet
Author: User

(i) Control of file types
This is just a demonstration of the type of picture control, other controls need to see webroot/fckeditor/editor/dialog/below the corresponding JS file
fckeditor.properties Writing Reference fckeditor-java-core-2.4.1.jar/net.fckeditor.handlers/net.fckeditor.handlers/ Default.properties file
Myconfig.js Writing Reference Webroot/fckeditor/fckconfig.js file

If you want to add a new type of picture such as. ABC, modify the following method:
Add attribute connector.resourceType.image.extensions.allowed = Bmp|gif|jpeg|jpg|png in fckeditor.properties |ABC
Add fckconfig.imageuploadallowedextensions = "in Myconfig.js. (jpg|gif|jpeg|png|bmp |ABC)$" ;

(ii) control of file size

Modify the judgment before uploading files in Connectorservlet.java

try {                     list<fileitem> items = upload.parserequest (Request);                      fileitem uplfile = items.get (0);                      string rawname = utilsfile.sanitizefilename (Uplfile.getname ());                      string filename = filenameutils.getname (Rawname);                      string basename = filenameutils.removeextension (filename);                     String extension =  Filenameutils.getextension (filename);                       //If this file extension is not allowed to uploadif (! extensionshandler.isallowed (resourcetype, extension)) ur = new Uploadresponse (uploadresponse.sc_in Valid_extension);    //If the file size exceeds the limitelse if (uplfile.getsize () >10*1024) {   //Pass a custom error code 204ur = new Uploadresponse (204); }   //If this is not the case, save the                      else {                         filename=uuid.randomuuid (). toString () + "." +extension;                          file pathtosave = new file (CurrentDir, filename);                          int counter = 1;                          while  (Pathtosave.exists ())  {                             newfilename =  Basename.concat ("("). Concat (string.valueof (counter))                                       .concat (")"). Concat ("."). concat (extension);                              pathtosave = new file (CurrentDir,  newfilename);                              counter++;                          }                          if  (Utils.isempty (newfilename))                              ur  = new uploadresponse (Uploadresponse.sc_ok, utilsresponse                                       .constructresponseurl (Request, &NBSP;RESOURCETYPE,&NBSP;CURRENTFOLDERSTR,                                               true,  Connectorhandler.isfullurl ()). CoNCAT (filename));                          else                              ur  = new uploadresponse (uploadresponse.sc_renamed,                                       utilsresponse.constructresponseurl (request,  ResourceType,                                               currentFolderStr, true,  Connectorhandler.isfullURL ())                                               .concat (NewFileName),  newfilename);                          if  (Resourcetype.equals (resourcetypehandler.image)                                   &&  Connectorhandler.issecureimageuploads ())  {                             if   (Utilsfile.isimage (Uplfile.getinputstream ())                                  uplfile.write (PathToSave);                              else {                                  uplfile.delete ();                                  ur = new  Uploadresponse (uploadresponse.sc_invalid_extension);                              }                          } else                               uplfile.write (Pathtosave);                      }                 }  catch  (exception e) handles custom errors in Webroot/fckeditor/editor/dialog/fck_image/fck_image.js.
Switch (errornumber) {case 0://No errors Alert ( ' File upload success ');             break ;         case 1 :    // Custom  Error             alert ( customMsg )  ;             return ;         case 101 :  // custom warning             alert ( customMsg )  ;             break ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CASE&NBSP;201&NBSP:              alert (  ' a file with the same name is  Already available. the uploaded file has been renamed to  "'  + fileName +  '" '  )  ;             break ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CASE&NBSP;202&NBSP:              alert (  ' invalid file type '  )  ;             return ; &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CASE&NBSP;203&NBSP:              alert (  "Security error. you probably don ' T have  enough permissions to upload. please check your server. "  )  ;             return ;          Case 204: alert ("Picture file size exceeds 10K");return;             Case 500:alert (' The connector is disabled ');         break; Default:alert (' Error on file upload.             Error number: ' + errornumber ';     return; If you limit the other types of file size, you need to go to the webroot/fckeditor/editor/dialog/directory to modify the corresponding JS file.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.