一個常用的東西,php+CKFinder上傳中文名文件亂碼問題的解決方法 這種問題主要是上傳中文文件名的圖片時出現亂碼的解決辦法。
上傳中文名文件亂碼問題:在ckfinder/config.php中找到如下一段配置代碼:
- /*
- If you have iconv enabled (visit http://php.net/iconv for more information),
- you can use this directive to specify the encoding of file names in your
- system. Acceptable values can be found at:
- http://www.gnu.org/software/libiconv/
- Examples:
- $config['FilesystemEncoding'] = 'CP1250';
- $config['FilesystemEncoding'] = 'ISO-8859-2';
- */
- $config['FilesystemEncoding'] = 'UTF-8';
將UTF-8修改為GB2312,上傳后文件名正確了,但在CKEditor中顯示的鏈接出現亂碼,因為CKEditor所在頁面使用的字符集是UTF-8,未去細究如何解決這個問題,采用了文件重命名的方案去替代解決。
上傳文件重命名:修改ckfindercoreconnectorphpphp5CommandHandlerFileUpload.php,找到以下代碼:
- if ($sFileName != $sUnsafeFileName) {
- $iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
- }
在這段代碼之后添加
- $sExtension=CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
- $sFileName=date('YmdHis').'.'.$sExtension;
新聞熱點
疑難解答