doulou9927 2018-02-26 04:30
浏览 61
已采纳

使用错误的文件编码上传CKEditor文件(不是UTF-8)

I am using PHP 5.6 on Windows IIS. When creating a link and uploading a file for that link through ckeditor, file name on server is not with special characters like: ČĆŽŠĐ. Problem is only when uploading files through ckeditor. When uploading text to database, there is no problem with the encoding. How can I make ckeditor to maybe tell server the right encoding, maybe to include encoding i request, or whatever I need to do to make it work? This PHP encoding is a nightmare!

I've fixed it with this:

iconv("utf-8", "cp1250", $_FILES['upload']['name'])

But, is there no way I can tell PHP to just treat everything as UTF-8? I've tried setting every single setting regarding encoding and codepage in php.ini to UTF-8 and it did not help. It really seems inconsistent and finicky. Any PHP experts that can tell me the simple solution to this mess?

These are the upload headers:

POST https://nsdmup-a.hr/cms/news_fileupload.php?CKEditor=fullText&CKEditorFuncNum=1&langCode=en HTTP/1.1
Host: nsdmup-a.hr
Connection: keep-alive
Content-Length: 1069214
Cache-Control: max-age=0
Origin: https://nsdmup-a.hr
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundarysc0FA4jsjDe2Z4s8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: https://nsdmup-a.hr/cms/news_add.php?editId=293
Accept-Encoding: gzip, deflate, br
Accept-Language: hr-HR,hr;q=0.9,en-US;q=0.8,en;q=0.7,sr;q=0.6,bs;q=0.5,ja;q=0.4
Cookie: PHPSESSID=45iuc1r017sb75bte57dl0te71

------WebKitFormBoundarysc0FA4jsjDe2Z4s8
Content-Disposition: form-data; name="upload"; filename="511-D-022-2018. dopis ministru - zapšljavanje namještenika2.pdf"
Content-Type: application/pdf

This is the file name he wrote to disk: "511-D-022-2018. dopis ministru - zapšljavanje namještenika2.pdf"

展开全部

  • 写回答

1条回答 默认 最新

  • dongtan6336 2018-02-26 06:05
    关注

    To my experience, this is a problem with Windows and all PHP versions up until v7.0

    So, either you continue using iconv function or upgrade PHP to at least v7.1 (changelog regarding Windows)

    You can also create a helper function with contents like this:

    if (version_compare(phpversion(), '7.1.0', '<') and strtoupper(substr(php_uname('s'), 0, 3)) === 'WIN')
    {
        // Windows and PHP 7.0 or less. Use iconv
        return iconv('utf-8', 'cp1250', $filename);
    }
    else
    {
        // Should be all good
        return $filename;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部