Home > Backend Development > PHP Tutorial > How to limit the size of image files uploaded by ckeditor_PHP tutorial

How to limit the size of image files uploaded by ckeditor_PHP tutorial

WBOY
Release: 2016-07-13 10:25:05
Original
1013 people have browsed it

One method can be limited by modifying the upload size of the PHP.INI configuration file. The other method can only 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 upload. Image size, here in KB
1. $Config['MaxImageSize']= '1024';
2. Open commands.php in the editor/filemanager/connectors/php directory and find

Copy code The code is as follows:

if ( isset( $Config['SecureImageUploads'] ) )
{
if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
{
$sErrorNumber = '202' ;
}
//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 into KB, and then compares whether it exceeds the specified image size. If it exceeds, an error will be reported.
Note that at the end, copy the code
as follows:
if ( !$sErrorNumber && IsAllowedExt( $sExtension, $ resourceType ) )
{
//Fckeditor upload image function
}
else
$sErrorNumber = '202' ;


else statement at the end of the code block Remove it, otherwise the function of limiting the size of image files uploaded by Fckeditor cannot be realized.
3. Open editor/dialog/fck_image/fck_image.js, add error code (errorNumber) information, find the OnUploadCompleted function, add


Copy code code As follows:
case 204:
alert( "Security error. File size error." ) ;
return ;


This restricts Fckeditor from uploading image files. The size configuration is complete. The same idea is used for other types of upload file size limits.

http://www.bkjia.com/PHPjc/825215.html

truehttp: //www.bkjia.com/PHPjc/825215.htmlTechArticleOne method can be limited by modifying the PHP.INI configuration file upload size, and the other method can only manually modify Fckeditor Source code, the method is as follows to open co in the editor/filemanager/connectors/php directory...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template