doulou9927
2018-02-26 12: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"

图片转代码服务由CSDN问答提供 功能建议

我在Windows IIS上使用PHP 5.6。 当通过ckeditor创建链接并上传该链接的文件时,服务器上的文件名不具有以下特殊字符:ČĆŽŠĐ。 只有通过ckeditor上传文件时才会出现问题。 将文本上载到数据库时,编码没有问题。 如何让ckeditor告诉服务器正确的编码,可能包括我请求的编码,或者我需要做些什么来使它工作? 这个PHP编码是一场噩梦!

我用它修复了它:

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

但是,我无法告诉PHP将所有内容视为UTF-8 ? 我已经尝试将关于php.ini中的编码和代码页的每个设置设置为UTF-8,但它没有帮助。 它看起来似乎不一致和挑剔。 任何可以告诉我这个混乱的简单解决方案的PHP专家?

这些是上传标题:

  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,与Gecko一样)Chrome / 64.0.3282.186 Safari / 537.36 
接受: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 \  nAccept-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 = “上传”;  filename =“511-D-022-2018.dipis ministru  - zapšljavanjenamještenika2.pdf”
Content-Type:application / pdf 
   
 
 

这是他的文件名 写信给磁盘: “511-D-022-2018.dipis ministru - zapĹljavanjenamjeĹtenika2.pdf”

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongtan6336 2018-02-26 14: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;
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题