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

Jul 13, 2016 am 10:25 AM
ckeditor upload image File size

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...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Create a rich text editor using PHP and CKEditor Create a rich text editor using PHP and CKEditor May 11, 2023 pm 04:06 PM

With the widespread use of web applications, creating rich text editors has become more and more common. CKEditor is widely recognized as one of the best rich text editors because of its good customizability and ease of use. This article will introduce how to create a rich text editor using PHP and CKEditor. Introduction to CKEditor CKEditor is an open source, cross-platform rich text editor implemented through JavaScript. It provides an intuitive and easy-to-understand toolbar, including font style, formatting, graphics, etc.

Java program to get the size of a given file in bytes, kilobytes and megabytes Java program to get the size of a given file in bytes, kilobytes and megabytes Sep 06, 2023 am 10:13 AM

The size of a file is the amount of storage space that a specific file takes up on a specific storage device, such as a hard drive. The size of a file is measured in bytes. In this section, we will discuss how to implement a java program to get the size of a given file in bytes, kilobytes and megabytes. A byte is the smallest unit of digital information. One byte equals eight bits. One kilobyte (KB) = 1,024 bytes, one megabyte (MB) = 1,024KB, one gigabyte (GB) = 1,024MB and one terabyte (TB) = 1,024GB. The size of a file usually depends on the type of file and the amount of data it contains. Taking a text document as an example, the file size may be only a few kilobytes, while a high-resolution image or video file may be

Get file size using filesize() function in PHP Get file size using filesize() function in PHP Jun 27, 2023 pm 03:14 PM

PHP is a server-side scripting language widely used in web development and is designed to provide support for the creation of dynamic web pages. One of the commonly used operations is to get the file size. File size is important to web developers as they need to ensure that the content of their website is not too large to impact the user experience. In PHP, you can use the filesize() function to get the file size. The syntax of this function is as follows: filesize(string$filename):float

How to post pictures on Douyin comments How to post pictures on Douyin comments Feb 19, 2024 pm 01:10 PM

As one of the most popular short video sharing platforms in the world, Douyin has attracted hundreds of millions of users to join it. When looking at other people's wonderful works, we are often moved by some dynamic, interesting or meaningful moments in them. At this time, we can not only express our opinions and thoughts through text comments, but also express our emotions more vividly through picture comments. So, how to post picture comments on TikTok? First, open the Douyin APP and enter the video you are interested in. Next, we need to determine the operating system of the mobile phone according to the different

PHP image operation: how to get the size and file size of images PHP image operation: how to get the size and file size of images Aug 26, 2023 am 08:55 AM

PHP Image Operation: How to Get the Size and File Size of Images In developing websites or applications, we often need to process images. Obtaining the size and file size of images is a common requirement, which can be easily achieved through some functions in PHP. This article will introduce how to use PHP to obtain the size and file size of images, and attach a code example. Get the image size To get the image size, you can use PHP's built-in function getimagesize(). This function will return a file containing the image size

How to get file size using C++? How to get file size using C++? Jun 01, 2024 pm 02:22 PM

Question: How to get file size in C++? Answer: 1. Use the std::ifstream::tellg() member function to get the number of bytes read or written since opening the file stream; 2. Use std::filesystem::directory_iterator to traverse the files in the directory, and Use std::ifstream::tellg() to calculate the number of bytes in each file and add them up to get the total size.

How to compare the file sizes of compressed packages through PHP ZipArchive? How to compare the file sizes of compressed packages through PHP ZipArchive? Jul 21, 2023 pm 06:07 PM

How to compare the file sizes of compressed packages through PHPZipArchive? In actual development, we may need to compare the sizes of files in the compressed package in order to process them accordingly. PHP provides the ZipArchive class, which can easily operate on compressed packages. This article will introduce how to use PHPZipArchive to compare the file sizes in compressed packages. First, we need to make sure that the PHP Zip extension is installed and enabled. This can be done via phpinfo(

Let's talk about how to use php to upload images Let's talk about how to use php to upload images Mar 28, 2023 am 11:28 AM

With the development of the Internet, image uploading has become one of the most common functions in website development. It is very simple to use the PHP language to implement the image upload function. As long as you have a certain basic knowledge of PHP, you can easily complete this task. This article will introduce how to use php to upload images

See all articles