Home Backend Development PHP Tutorial Solution to garbled images uploaded by fckeditor_PHP tutorial

Solution to garbled images uploaded by fckeditor_PHP tutorial

Jul 13, 2016 am 10:55 AM
php upload Chinese Garbled characters use picture Tutorial method of solve

php tutorial Chinese garbled code

Chinese name is garbled because:
FCKeditor uses UTF-8 encoding,
For example, if your machine is a Windows system
The file name uses GBK encoding,
When uploading, you need to change the encoding from UTF-8 to GBK


==>The first idea, the transcoding idea, needs to modify two files, the first file:
.fckeditoreditorfilemanagerconnectorsphpcommands.php file

There is a FileUpload function inside:

move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;
Change to
move_uploaded_file( $oFile['tmp_name'], iconv("utf-8","gbk",$sFilePath) ) ;

----------

Second file:

.fckeditoreditorfilemanagerconnectorsphputil.php file

Find the ConvertToXmlAttribute function:

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

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

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

Needs to be modified as follows:

In the .fckeditoreditorfilemanagerconnectorsphpcommands.php file

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

Modify as follows:

//--------------------------------------------- ------------------
//Method 2 to correct garbled Chinese characters in uploaded files: (Modify the name of the uploaded file)
$sFileName = "sda.php";
$sOriginalFileName = $sFileName;
$sExtension = substr($sFileName, (strrpos($sFileName, '.') + 1));//Find extension
$sExtension = strtolower($sExtension);
$sFileName = date("YmdHis").rand(100, 200).".".$sExtension;
//------------------------------------------------ ---------------

Personally, I think the first method is pretty good!


java version

When using FCKeditor2.4.3, if the uploaded image or flash file name is Chinese, I found the following situation:
Question 1:
When clicking the "Insert/Edit Image" or "Insert/Edit Flash" button, select the upload button in the pop-up dialog box. If the uploaded file name is in Chinese, garbled characters will appear.
Solution:
Modify SimpleUploaderServlet.java as follows:
Find DiskFileUpload upload = new DiskFileUpload() in the program, and then add
below this line upload.setHeaderEncoding("UTF-8")
Question 2:
When clicking the "Insert/Edit Image" or "Insert/Edit Flash" button, use Browse in the pop-up dialog box
Garbled characters appear when the server button uploads Chinese files.
Solution:
The solution to problem 1 is basically the same, except that you need to add
to ConnectorServlet.java upload.setHeaderEncoding("UTF-8") will do.
Question 3:
When clicking the "Insert/Edit Image" or "Insert/Edit Flash" button, click Browse in the pop-up dialog box
Server button, the "Browse Server" page will pop up, if you want to use the Create New Folder button in this page
When creating a Chinese directory, the Chinese directory will be garbled.
Solution:
The encoding of the web container must be consistent with FCKeditor’s default encoding UTF-8. If you are using Tomcat, you need to modify it
server.xml in the conf directory in 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, it is to add the attribute value of URIEncoding to utf-8 on the original basis.

When using FCKeditor2.4.3, if the uploaded image or flash file name is Chinese, I found the following situation:
Question 1:
When clicking the "Insert/Edit Image" or "Insert/Edit Flash" button, select the upload button in the pop-up dialog box. If the uploaded file name is in Chinese, garbled characters will appear.
Solution:
Find SimpleUploaderServlet.java in the src directory in the FCKeditor.java decompression package and make the following modifications:
Find DiskFileUpload upload = new DiskFileUpload() in the program, and then add
below this line upload.setHeaderEncoding("UTF-8"), recompile it into a class file and use WinRAR to convert the class file
Add it to the corresponding location in FCKeditor-2.3.jar, and then overwrite the original jar package in your web project.
Question 2:
When clicking the "Insert/Edit Image" or "Insert/Edit Flash" button, use Browse in the pop-up dialog box
Garbled characters appear when the server button uploads Chinese files.
Solution:
The solution to problem 1 is basically the same, except that you need to add
to ConnectorServlet.java upload.setHeaderEncoding("UTF-8") will do.
Question 3:
When you click the "Insert/Edit Image" or "Insert/Edit Flash" button, click Browse in the pop-up dialog box
Server button will pop up the "Browse Server" page. If you want to use the Create New Folder button in this page
When creating a Chinese directory, the Chinese directory will be garbled.
Solution:
The encoding of the web container must be consistent with FCKeditor’s default encoding UTF-8. If you are using Tomcat, you need to modify it
server.xml in the conf directory in 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, it is to add the attribute value of URIEncoding to utf-8 on the original basis.
Note: For question 3, this solution is not advisable. It is best not to modify the server encoding, otherwise it will affect other projects on the server. To solve this coding problem, you can modify the source code or rewrite a class to handle it. By observing the opened upload browsing dialog box, you can find the corresponding htm page and the com.fredck.FCKeditor.uploader. ConnectorServlet class responsible for processing the uploaded file name, and then find the corresponding parameters and convert the encoding. Such as: String

newFolderStr=request.getParameter("NewFolderName");

newFolderStr=new String(newFolderStr.getBytes("iso8859-1"),"utf-8");
================================================== ===============================

fckeditor If everyone gets it done1! Then you must think that he does not provide a delete function! !
The following is a piece of js, 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 < imgs.length; i++){
alert(imgs[i].src);

//Here you can use a hidden domain to receive these path information
}
}
Put these path information in a field in the database tutorial, delete it together when deleting the document, you can solve the image retention problem
================================================== ======================================
Avoid the appearance of up and down scroll bars:


Add the following 2 sentences to fckconfig.js:

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

At the same time, please confirm that fckeditoreditorpluginsautogrow has this directory. If not, go to the official website to download the latest version of FCK.


Also pay attention to whether you have set the path of FCKConfig.PluginsPath correctly.
================================================== =========================

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

This is correct, it is the system default path and there is no problem using FCK

It just can’t adjust the height automatically
================================================== ===========================

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


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

================================================== =========================
If it doesn't work, have you ever changed the source code of FCK?
You can re-download the file, change only these two lines and test it. You don't need to change anything else to achieve what you asked for.

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

Question 2

FCKeditor Chinese garbled problem

When using FCKeditor, there are three main places where Chinese garbled characters appear:

① When creating a new directory in the "Browse Server" page

Problem: When you click "Insert/Edit Image" or "Insert/Edit Flash", the "Image Properties" or "Flash Properties" dialog box will pop up, and then click the "Browse Server" button in it. The "Browse Server" page will open. When creating a Chinese name directory on this page, garbled characters will appear.

Solution: Modify the character encoding of the web container. Because the default character encoding of FCKeditor is UTF-8, the character encoding of the Web container is also changed to 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 in the "Browse Server" page

Problem: When uploading files with Chinese names in the "Browse Server" page opened in the same way as ①, garbled characters will appear.

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

Problem: When you click "Insert/Edit Image" or "Insert/Edit Flash", the "Image Properties" or "Flash Properties" dialog box will pop up. Click the "Upload" tab and click "Browse" ..." button, select a file with a Chinese name, and then click the "Send to server" button. The uploaded file name is garbled.

Solution: Modify the FCKeditor.Java source code. It is more convenient to modify the source code through Eclipse and then repackage it into a jar file. Create a new Web project FCKeditor-java-2.3 in Eclipse. Note here that because the WebRoot directory name of FCKeditor.Java is web, it is recommended that when creating a new project, the WebRoot directory name should also be named web. Copy the corresponding directory in FCKeditor.Java to the project. Find the two files ConnectorServlet.java and SimpleUploaderServlet.java in src, find DiskFileUpload upload = new DiskFileUpload(); in the two files respectively, and add upload.setHeaderEncoding("utf-8"); after them. Then copy catalina-ant.jar in /server/lib in the Tomcat installation directory to /WEB-INF/lib in 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 the Outline window of Eclipse, and a new FCKeditor-2.3.jar will be generated. Replace FCKeditor-2.3.jar in the project using FCKeditor with this new one.

Upload failure problem

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

In addition, FCKeditor will automatically create the directory specified by the parameter baseDir of SimpleUploader in web.xml. When uploading files through the "Browse Server" page, if there is no corresponding Image or Flash directory under baseDir, FCKeditor will automatically create the Image or Flash directory; however, when uploading files through the "Send to Server" button in the "Upload" tab If there is no corresponding Image or Flash directory under baseDir, FCKeditor will report an error. In this case, you need to manually create a new Image or Flash directory under baseDir


In summary, whether it is jsp, php, asp tutorial.net problems, we need to analyze them as follows

Yes, it is a Chinese encoding problem, there are two ways to solve it
You need to change the corresponding file source code of fck
1 Convert the string encoding of the Chinese name

2 Rename the file name in English and add numbers


I haven’t looked at the code and forgot about that file name, and it seems to be slightly different depending on the version. You should be able to find it out if you do some research

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632286.htmlTechArticlephp tutorial Chinese garbled Chinese name is garbled because: FCKeditor uses UTF-8 encoding, and your machine is a Windows system file. The name uses GBK encoding, which is required when uploading. Change the encoding from UT...
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 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
1664
14
PHP Tutorial
1266
29
C# Tutorial
1239
24
Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

See all articles