Garbled image file name uploaded by FCK in PHP_PHP tutorial

WBOY
Release: 2016-07-13 10:57:02
Original
713 people have browsed it

Friends who use fck may encounter such a situation. If you upload your file name with English letters, there is no problem. If you upload Chinese characters, the Chinese name will be garbled. Let me analyze and introduce it to you. Solution.

The main reason is that the encoding (utf-8) code in fck is inconsistent with the local encoding (gbk). This can be solved by modifying the following 5 files

Change the FileUpLoad function ckeditor/" target="_blank">fckeditoreditorfilemanagerconnectorsphpcommands.php

Find the following code in the file:

The code is as follows
 代码如下 复制代码

// Get the extension.  
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;  
$sExtension = strtolower( $sExtension ) ; 

Copy code

 代码如下 复制代码

$sFileName = strtotime('now').'.'.$sExtension; 

// Get the extension.
$sExtension = substr( $sFileName, ( strrpos($sFileName, '.') + 1 ) ) ;
$sExtension = strtolower( $sExtension ) ;

Add a sentence after it:

Found
The code is as follows

Copy code
 代码如下 复制代码

function FileUpload( $resourceType, $currentFolder, $sCommand ){

。。。

      找到

      //move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ;

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

}

$sFileName = strtotime('now').'.'.$sExtension;

In this way, the file name is the current timestamp + suffix name. It not only solves Chinese garbled characters, but also solves the problem of duplicate file names

Another solution, keep the Chinese name
 代码如下 复制代码

function ConvertToXmlAttribute( $value ){

       。。。

       找到

      //return ( utf8_encode( htmlspecialchars( $value ) ) ) ;

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

}

File 4: fckeditoreditorfilemanagerconnectorsphpcommands.php

The code is as follows
Copy code

function FileUpload( $resourceType, $currentFolder, $sCommand ){. . . Found //move_uploaded_file( $oFile['tmp_name'], $sFilePath ) ; move_uploaded_file( $oFile['tmp_name'], iconv("utf-8","gbk",$sFilePath)); }
Transcode the file name $sFilePath.
File 5: fckeditoreditorfilemanagerconnectorsphputil.php Found
The code is as follows Copy code
function ConvertToXmlAttribute( $value ){ . . . Found //return ( utf8_encode( htmlspecialchars( $value ) ) ) ; return iconv("GBK", "UTF-8", htmlspecialchars( $value )); } Transcode content. http://www.bkjia.com/PHPjc/632133.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632133.htmlTechArticleFriends who use fck may encounter a situation where there is no problem if your file is named with English letters. , if you upload Chinese characters, the Chinese name will be garbled, next...
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!