Home Backend Development PHP Tutorial 限制ckeditor上传图片文件大小的方法_PHP

限制ckeditor上传图片文件大小的方法_PHP

Jun 01, 2016 am 11:57 AM
ckeditor upload image File size

FCKEditor

一种可以通过修改PHP.INI配置文件上传大小来限制,另一种方法只能手动修改Fckeditor源码,方法如下
打开editor/filemanager/connectors/php目录下config.php,创建Config变量设置上传图片大小,这里以KB为单位
1、$Config['MaxImageSize']= '1024';
2、打开editor/filemanager/connectors/php目录下commands.php,找到
复制代码 代码如下:
if ( isset( $Config['SecureImageUploads'] ) )
{
if ( ( $isImageValid = IsImageValid( $oFile['tmp_name'], $sExtension ) ) === false )
{
$sErrorNumber = '202' ;
}
//上传图片大小限制
}
在上传图片大小限制处,添加
if ( isset( $Config['MaxImageSize'] ) )
{
$iFileSize = round( $oFile['size'] / 1024 );
if($iFileSize > $Config['MaxImageSize'] )
{
$sErrorNumber = '204';
}
}
 
说明:由于PHP计算上传图片大小以字节为单位,所以代码首先将上传的图片大小折算为KB,再来对比是否超出了规定的图片大小,如超出,则报错。
注意最后将
复制代码 代码如下:
if ( !$sErrorNumber && IsAllowedExt( $sExtension, $resourceType ) )
{
//Fckeditor上传图片功能
}
else
$sErrorNumber = '202' ; 

代码块结尾处的else语句去除,否则实现不了限制Fckeditor上传图片文件大小的功能。
3、打开editor/dialog/fck_image/fck_image.js,添加错误代码(errorNumber)信息,找到OnUploadCompleted函数,添加
复制代码 代码如下:
case 204 :
alert( "Security error. File size error." ) ;
return ; 

至此限制Fckeditor上传图片文件大小配置就完成了,其他类型的上传文件大小限制也是这种思路。
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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 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)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1270
29
C# Tutorial
1249
24
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

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.

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

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

How to determine the file size of a compressed package through PHP ZipArchive? How to determine the file size of a compressed package through PHP ZipArchive? Jul 21, 2023 pm 08:33 PM

How to determine the file size of compressed packages through PHPZipArchive? Summary: PHP's ZipArchive class is a very useful tool that can be used to create, modify and extract compressed archives. However, sometimes we may need to judge the file size in the compressed package so that we can be prepared when dealing with large files. In this article, we will learn how to determine the size of the files in the compressed package through PHP's ZipArchive class. Steps: First, we need to create a Z

Let's talk about how to use ueditor to upload pictures and add watermarks Let's talk about how to use ueditor to upload pictures and add watermarks Aug 31, 2022 am 10:35 AM

How to upload pictures with ueditor and add watermark? The following article will introduce to you how to use ueditor to upload pictures and add watermarks in PHP. I hope it will be helpful to you!

See all articles