一个常用的东西,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,未去细究如何解决这个问题,采用了文件重命名的方案去替代解决。
上传文件重命名
立即学习“PHP免费学习笔记(深入)”;
修改ckfindercoreconnectorphpphp5CommandHandlerFileUpload.php
找到以下代码
<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
<tr>
<td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
<td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy3782')">复制代码</td>
</tr>
<tr>
<td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3782><pre class="code">if ($sFileName != $sUnsafeFileName) {
$iErrorNumber = CKFINDER_CONNECTOR_ERROR_UPLOADED_INVALID_NAME_RENAMED;
}<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7">
<tr>
<td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td>
<td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onClick="doCopy('copy3357')">复制代码</td>
</tr>
<tr>
<td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy3357><pre class="brush: php; title: ; notranslate" title="">$sExtension=CKFinder_Connector_Utils_FileSystem::getExtension($sFileName);
$sFileName=date('YmdHis').'.'.$sExtension;
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号