How to restrict the size of image files uploaded by ckeditor

Source: Internet
Author: User
The method in this article solves the problem of how to restrict the size of the image file uploaded by ckeditor. the specific steps are as follows. for details, refer to use FCKEditor.

One method can be used to limit the size of the PHP. INI configuration file to be uploaded. The other method can only be used to manually modify the Fckeditor source code. the method is as follows:
Open config. php in the editor/filemanager/connectors/php directory and create a Config variable to set the size of the uploaded image. the unit is KB.
1. $ Config ['maximagesize'] = '000000 ';
2. open commands. php in the editor/filemanager/connectors/php directory and find
The code is as follows:
If (isset ($ Config ['secureimageupload'])
{
If ($ isImageValid = IsImageValid ($ oFile ['tmp _ name'], $ sExtension) === false)
{
$ SErrorNumber = '123 ';
}
// Size limit of uploaded images
}
Add
If (isset ($ Config ['maximagesize'])
{
$ IFileSize = round ($ oFile ['size']/1024 );
If ($ iFileSize> $ Config ['maximagesize'])
{
$ SErrorNumber = '123 ';
}
}

Note: Because PHP calculates the size of the uploaded image in bytes, the code first converts the size of the uploaded image to KB, and then compares whether the size of the uploaded image exceeds the specified size, an error is returned.
Note that
The code is as follows:
If (! $ SErrorNumber & IsAllowedExt ($ sExtension, $ resourceType ))
{
// Fckeditor uploads images
}
Else
$ SErrorNumber = '123 ';

Remove the else statement at the end of the code block. Otherwise, the Fckeditor cannot limit the size of the image file to be uploaded.
3. open editor/dialog/fck_image/fck_image.js, add the error code (errorNumber), find the OnUploadCompleted function, and add
The code is as follows:
Case 204:
Alert ("Security error. File size error .");
Return;

So far, the Fckeditor can be configured to limit the size of image files to be uploaded. this is also the idea of limiting the size of other types of uploaded files.

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.