php+CKFinder上传中文名文件乱码问题的解决方法
一个常用的东西,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;