For PHP Environment FCKeditor editor upload picture Configuration Detail Tutorial _ page Editor

Source: Internet
Author: User
Tags error code file size file upload rand

Open FCKeditor upload image function

In view of the directory security issues, The default Fckeditor2.6.6 upload function is not turned on, so the first step we must open the FCKeditor upload function, here need to pay attention, because the PHP version FCKeditor upload function to use the CHOMOD function to the new directory to set permissions, so be sure to make sure that the FCKeditor on the Enable The user of the PHP environment has permission to create and change the uploaded directory when the function is passed.

If you do not turn on the FCKeditor upload function, click the Insert/Edit image button, select Upload, after the selection of files to upload and click to send to the server button will be reported as the following error message

Copy Code code as follows:

This file uploader is disabled.
Please check the "editor/filemanager/connectors/php/config.php" file

According to the error message, open the editor/filemanager/connectors/php directory config.php, find

Copy Code code as follows:

$Config [' Enabled '] = false;

Change to

Copy Code code as follows:

$Config [' Enabled '] = true;

and in the corresponding directory to build userfiles upload directory, FCKeditor upload image function open.

Special reminder: Fckeditor seems to have a bug, that is, JS compatibility is not too perfect, before I set up in Google Chrome browser, Fckeditor PHP upload has not been realized, changed IE after all normal.

FCKeditor Upload Path Configuration tutorial when uploading pictures

As an independent web developer, in addition to considering the technology also need to take into account other convenience, such as SEO optimization, and directory structure (URL) optimization is part of the SEO, this need to be in the settings FCKeditor upload picture features to consider the image upload path problem.

The default FCKeditor image upload path structure has two forms: userfiles/file name and userfiles/file type/filename, for two fckeditor upload methods: Fast upload (image attributes in the upload) and server tour upload (image properties in the link), For example, upload pictures, quickupload mode upload path for userfiles/filename, server tour upload mode upload path for userfiles/images/file name.

FCKeditor image upload path is configured as follows

Open the config.php file in the editor/filemanager/connectors/php directory and find

Copy Code code as follows:

$Config [' userfilespath '] = '/userfiles/';

Change to

Copy Code code as follows:

$Config [' userfilespath '] = '/project directory/userfiles/';

Note: The Userfiles folder here is for the http://localhost/root directory.

Above is the default FCKeditor upload path configuration, according to the URL planning you can customize FCKeditor upload directory, as long as the config.php file in the $config[' Filetypespath ', $Config [' Filetypesabsolutepath '], $Config [' Quickuploadpath '], $Config [' Quickuploadabsolutepath '] Four upload directory path values. This method to a certain extent also can avoid fckeditor upload picture file name problem.

Limit fckeditor upload picture size settings

Fckeditor2.6.6 default does not limit the size of uploaded picture files, can be improved by two methods, one can be modified php.ini configuration file upload size to limit, another method can only manually modify the FCKeditor source code, the following methods

1, open the editor/filemanager/connectors/php directory config.php, create config variable set upload picture size, here in kilobytes

Copy Code code as follows:

$Config [' maximagesize ']= ' 1024];

2, open the editor/filemanager/connectors/php directory under commands.php, find

Copy Code code as follows:

if (Isset ($Config [' secureimageuploads '])
{
if ($isImageValid = Isimagevalid ($oFile [' Tmp_name '], $sExtension) = = False)
{
$sErrorNumber = ' 202 ';
}
Upload picture size limit
}

In the upload picture size limit, add

Copy Code code as follows:

if (Isset ($Config [' maximagesize '])
{
$iFileSize = Round ($oFile [' size ']/1024);
if ($iFileSize > $Config [' maximagesize '])
{
$sErrorNumber = ' 204 ';
}
}

Description: Because the PHP calculation upload image size in bytes, so the code will upload the picture size to KB, and then to compare whether the specified picture size, such as exceeded, the error.

Note that the final

Copy Code code as follows:

if (! $sErrorNumber && isallowedext ($sExtension, $resourceType))
{
FCKeditor Upload Image function
}
Else
$sErrorNumber = ' 202 ';

code block at the end of the Else statement removal, otherwise can not achieve limit fckeditor upload picture file size function.

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 limit fckeditor upload picture file size configuration is complete, other types of upload file size limit is also this idea.

FCKeditor upload image filename and Chinese garbled solution

After testing Fckeditor2.6.6 did not solve the upload file Chinese name into garbled problem, this is because the FCKeditor upload function and did not rename the file, easy to upload image files duplicate file name and garbled problem.

Upload image file Duplicate name and garbled solution is as follows

Open the editor/filemanager/connectors/php directory commands.php, find the FileUpload function,

Copy Code code as follows:

$sExtension = substr ($sFileName, (Strrpos ($sFileName, '. ') + 1));
$sExtension = Strtolower ($sExtension);

Add after

Copy Code code as follows:

$sFileName = rand (0,100). ".". $sExtension;

The RAND function here can change the renaming rules on its own.

Another upload image file name garbled solution to use the Iconv function to encode the file name, but there is still a duplicate name problem, so for fckeditor upload picture filename is best or renamed.

FCKeditor upload image Add watermark function

For the owner of the site to protect the copyright add watermark is necessary, we can use PHP to add a watermark function combined with FCKeditor file upload function FileUpload realize the image add watermark function, watermark function refer to the PHP picture watermark function: Support to the image and text to add a watermark text.

So fckeditor in the PHP environment upload Picture Configuration Introductory tutorial is finished.

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.