Fckeditor solution for uploading garbled images _ PHP Tutorial

Source: Internet
Author: User
Fckeditor uploads garbled images. Php Tutorial Chinese garbled Chinese name garbled because: FCKeditor using UTF-8 encoding, their own machine such as Windows system file name using GBK encoding, in the upload need, change the encoding, from UT php Tutorial Chinese garbled

The Chinese name is garbled because:
FCKeditor uses UTF-8 encoding,
Self-built machines, such as Windows systems
The file name uses GBK encoding,
Upload needs, change the encoding, from UTF-8 to GBK


==> The first idea is the transcoding idea. you need to modify two files. The first file:
. Fckeditoreditorfilemanagerconnectorsphpcommands. php file

There is a FileUpload function:

Move_uploaded_file ($ oFile ['tmp _ name'], $ sFilePath );
Change
Move_uploaded_file ($ oFile ['tmp _ name'], iconv ("UTF-8", "gbk", $ sFilePath ));

----------

The second file:

. Fckeditoreditorfilemanagerconnectorsphputil. php file

Find the ConvertToXmlAttribute function:

Return (utf8_encode (htmlspecialchars ($ value )));

Change to: return iconv ("GBK", "UTF-8", htmlspecialchars ($ value ));

==> The second idea is to modify the name of the uploaded file:

You need to modify it as follows:

In the. fckeditoreditorfilemanagerconnectorsphpcommands. php file

Find the FileUpload function: set $ sFileName = $ oFile ['name'];

Modify as follows:

//--------------------------------------------------------------
// Method 2 for correcting Chinese garbled characters in the uploaded file: (modify the name of the uploaded file)
$ SFileName = "sda. php ";
$ SOriginalFileName = $ sFileName;
$ SExtension = substr ($ sFileName, (strrpos ($ sFileName, '.') + 1); // locate the extension
$ SExtension = strtolower ($ sExtension );
$ SFileName = date ("YmdHis"). rand (100,200). ".". $ sExtension;
//--------------------------------------------------------------

I personally think the first method is quite good!


Java version

When FCKeditor2.4.3 is used, if the file name of the uploaded image or flash is medium, the following information is found:
Question 1:
When you click "Insert/edit image" or "insert/edit Flash", select the upload button in the pop-up dialog box. if the uploaded file name is Chinese, garbled characters will appear.
Solution:
Modify SimpleUploaderServlet. java as follows:
Find DiskFileUpload upload = new DiskFileUpload () in the program, and then add
Upload. setHeaderEncoding ("UTF-8 ")
Question 2:
Click "Insert/edit image" or "insert/edit Flash ".
Garbled characters may occur when the server button uploads a Chinese file.
Solution:
The solution is basically the same as the solution of problem 1, but you only need to add
Upload. setHeaderEncoding ("UTF-8.
Question 3:
When you click "Insert/edit image" or "insert/edit Flash", click browse in the pop-up dialog box.
The "browse server" page appears. if you want to use the "Create New Folder" button in the page
When you create a Chinese Directory, the Chinese Directory is garbled.
Solution:
The encoding of the web container should be consistent with the default encoding UTF-8 of FCKeditor, if Tomcat is used, you need to modify
Server. xml in the conf Directory of the tomcat server. As follows:

MaxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
EnableLookups tutorial = "false" redirectPort = "8443" acceptCount = "100"
ConnectionTimeout = "20000" disableUploadTimeout = "true" URIEncoding = "UTF-8"/>
EnableLookups = "false" redirectPort = "8443" protocol = "AJP/1.3" URIEncoding = "UTF-8"/>

In fact, the attribute value of URIEncoding is UTF-8.

When FCKeditor2.4.3 is used, if the file name of the uploaded image or flash is medium, the following information is found:
Question 1:
When you click "Insert/edit image" or "insert/edit Flash", select the upload button in the pop-up dialog box. if the uploaded file name is Chinese, garbled characters will appear.
Solution:
Find SimpleUploaderServlet. java under the src directory in the decompressed FCKeditor. java package and make the following changes:
Find DiskFileUpload upload = new DiskFileUpload () in the program, and then add
Upload. setHeaderEncoding ("UTF-8"), recompile it into a class file and use WinRAR
Add the appropriate location to the FCKeditor-2.3.jar and overwrite the original jar package in your web project.
Question 2:
Click "Insert/edit image" or "insert/edit Flash ".
Garbled characters may occur when the server button uploads a Chinese file.
Solution:
The solution is basically the same as the solution of problem 1, but you only need to add
Upload. setHeaderEncoding ("UTF-8.
Question 3:
When you click "Insert/edit image" or "insert/edit Flash", click browse in the pop-up dialog box.
The "browse server" page appears. if you want to use the "Create New Folder" button in the page
When you create a Chinese Directory, the Chinese Directory is garbled.
Solution:
The encoding of the web container should be consistent with the default encoding UTF-8 of FCKeditor, if Tomcat is used, you need to modify
Server. xml in the conf Directory of the tomcat server. As follows:

MaxThreads = "150" minSpareThreads = "25" maxSpareThreads = "75"
EnableLookups = "false" redirectPort = "8443" acceptCount = "100"
ConnectionTimeout = "20000" disableUploadTimeout = "true" URIEncoding = "UTF-8"/>
EnableLookups = "false" redirectPort = "8443" protocol = "AJP/1.3" URIEncoding = "UTF-8"/>

In fact, the attribute value of URIEncoding is UTF-8.
Note: For Issue 3, this solution is not advisable. it is recommended that you do not modify the server code, otherwise it will affect other projects on the server. To solve this encoding problem, you can modify the source code or write a new class. You can find the corresponding htm page and the com. fredck. FCKeditor. uploader. connectorServlet class, find the corresponding parameter, and convert the encoding. For example, String

NewFolderStr = request. getParameter ("NewFolderName ");

NewFolderStr = new String (newFolderStr. getBytes ("ISO8859-1"), "UTF-8 ");
========================================================== ========================================================== =

Fckeditor! He does not provide the delete function !!
Below is a piece of js, which is placed on the jsp tutorial page that calls feckeditor
Function FCKeditor_OnComplete (editorInstance)
{
EditorInstance. Events. AttachEvent ('onblur', onEditorBlur );
}

Function onEditorBlur (){
Var imgs = FCKeditorAPI. GetInstance ('editordefault'). EditorDocument. body. all. tags ("img ");
For (var I = 0; I Alert (imgs [I]. src );

// Here you can use a hidden domain to receive the path information
}
}
Place the path information in a field of the database tutorial. if you delete the document together, you can solve the problem of image persistence.
========================================================== ========================================================== ==========
Avoid the appearance of the upper and lower scroll bars:


Add the following two sentences to fckconfig. js:

FCKConfig. Plugins. Add ('autogrow ');
FCKConfig. AutoGrowMax = 4000; // This is the maximum height limit that allows automatic growth.

Make sure that the fckeditoreditorpluginsautogrow directory exists. if not, download the latest FCK from the official website.


Note that you have set the FCKConfig. PluginsPath path.
========================================================== ==========================================

FCKConfig. PluginsPath = FCKConfig. BasePath + 'ins ins /';

This is correct. the default path of the system is correct for FCK usage.

That is, the height cannot be adjusted automatically.
========================================================== ============================================

FCKConfig. PluginsPath = FCKConfig. BasePath + 'ins ins /';


This is the statement in js. BasePath is not set here. it is set when FCK is called in php.

========================================================== ======================================
If not, have you ever changed the FCK source code.
You need to re-download the file and test the changes. You don't need to modify anything else to implement what you said.

FCKConfig. Plugins. Add ('autogrow ');
FCKConfig. autogrowmax= 4000;

Question 2

FCKeditor Chinese garbled

In the use of FCKeditor, Chinese garbled characters may appear in three places:

① When creating a directory on the browser server page

Q: When you click "Insert/edit image" or "insert/edit Flash", the "image attribute" or "Flash attribute" dialog box is displayed, then, when you click the "browse server" button, the "browse server" page is displayed, and garbled characters appear when you create a Chinese name directory on this page.

Solution: modify the character encoding of the Web container. Because FCKeditor's default character encoding is a UTF-8, the Web container's character encoding is also modified to a UTF-8. If the Web container uses Tomcat, open the file % CATALINA_HOME %/conf/server. xml and modify it as follows:

Port = "8080"
RedirectPort = "8443"
MinSpareThreads = "25"
ConnectionTimeout = "60000"
ConnectionLinger = "-1"
ServerSoTimeout = "0"
MaxSpareThreads = "75"
MaxThreads = "150"
TcpNoDelay = "true"
MaxHttpHeaderSize = "8192"
IEncoding = "UTF-8">

Port = "8009"
RedirectPort = "8443"
Protocol = "AJP/1.3"
IEncoding = "UTF-8">

② When uploading files on the browser server page

Problem: garbled characters may occur when uploading a file with a Chinese name on the browser server page opened in the same way as ①.

Solution: open the file/editor/filemanager/browser/default/frmupload.html in the project WebRoot, and add a meta in the head:


③ When uploading files in the "image properties" or "Flash properties" dialog box

Q: When you click "Insert/edit image" or "insert/edit Flash", the "image attribute" or "Flash attribute" dialog box is displayed. click the "upload" tab, click browse... ", select a file with a Chinese name, and click" send to server ". the uploaded file name is garbled.

Solution: modify the source code of FCKeditor. Java. It is convenient to modify the source code through Eclipse and then package it into a jar file again. Create a Web project FCKeditor-java-2.3 in Eclipse. Note that because the WebRoot directory name of FCKeditor. Java is web, we recommend that you also name the WebRoot directory name web when creating a project. Copy the corresponding directory in FCKeditor. Java to the project. Find ConnectorServlet in src. java and SimpleUploaderServlet. in java, find DiskFileUpload upload = new DiskFileUpload () in the two files, and add upload. setHeaderEncoding ("UTF-8 ");. Then copy the catalina-ant.jar in the/server/lib directory of Tomcat installation to the/WEB-INF/lib of the project. Open build. xml and modify property name = "catalina. home" to the Tomcat installation directory. Modify taskdef name = "deploy", taskdef name = "list", taskdef name = "reload", taskdef name = "undeploy" as follows:

<

Taskdef name = "deploy" classname = "org. apache. catalina. ant. DeployTask">











Then run Ant's dist in Eclipse's Outline window to generate a new FCKeditor-2.3.jar. Replace the FCKeditor-2.3.jar in the project that uses FCKeditor with this new one.

Upload failure

The server side is not considered here. First, check whether the enabled parameter is set to false in the Servlet configuration of SimpleUploader in web. xml.

In addition, FCKeditor automatically creates the directory specified by the SimpleUploader parameter baseDir in web. xml. When a file is uploaded through the browser server page, if there is no corresponding Image or Flash directory under baseDir, FCKeditor will automatically create an Image or Flash directory; however, when you upload a file through the "send to server" button on the "upload" tab, if the baseDir does not have the corresponding Image or Flash Directory, FCKeditor reports an error, in this case, you need to manually create an Image or Flash object in baseDir.


To sum up, whether it is jsp, php, asp tutorial. net, we need to analyze the problem as follows:

Yes. There are two solutions to the Chinese encoding problem.
Both need to change the source code of the corresponding fck file
1. encode the string of the Chinese name

2. rename the file name with English letters and numbers


I have forgotten the code for the file name, and the version may be slightly different. you should be able to find out the file name.

Invalid Chinese name garbled because: FCKeditor uses UTF-8 encoding, their machine, such as Windows system file name using GBK encoding, upload needs, change the encoding, from UT...

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.