Ways to limit the size of ckeditor image files uploaded

  • 2020-11-25 07:12:22
  • OfStack

One can limit the PHP.INI configuration file upload size, and the other can only manually modify the Fckeditor source code as follows
Open config.php in editor/filemanager/connectors/php and create Config variable to set the size of the uploaded image, in KB here
1, $Config [' MaxImageSize] = '1024';
2, open the editor filemanager/connectors/php directory commands php, find it

if ( isset( $Config['SecureImageUploads'] ) ) 
{ 
if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false ) 
{ 
$sErrorNumber = '202' ; 
} 
// Upload image size limit  
} 
 In the upload image size limit, add 
if ( isset( $Config['MaxImageSize'] ) ) 
{ 
$iFileSize = round( $oFile['size'] / 1024 ); 
if($iFileSize > $Config['MaxImageSize'] ) 
{ 
$sErrorNumber = '204'; 
} 
}
 

Note: Since PHP calculates the uploaded image size in bytes, the code first converts the uploaded image size to KB, and then compares whether it exceeds the specified image size. If it does, it will report an error.
Notice that at the end

if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) ) 
{ 
//Fckeditor Upload image function  
} 
else 
$sErrorNumber = '202' ;  

The else statement at the end of the block is removed, otherwise the ability to limit the size of image files uploaded by Fckeditor cannot be achieved.
3. Open editor/dialog/fck_image/ fck_image.js, add error code (errorNumber), find OnUploadCompleted function and add
 
case 204 : 
alert( "Security error. File size error." ) ; 
return ;  

At this point limit Fckeditor upload image file size configuration is complete, other types of upload file size limit is the same idea.

Related articles: