Home > Article > Backend Development > Solution to garbled images uploaded by fckeditor_PHP tutorial
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 followsYes, 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 name2 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