UTF-8 text is garbled when form is posted as multipart/form-data in PHP

人走茶凉 提交于 2019-12-11 13:57:11

问题


I have a PHP script to publish articles. It was working perfectly fine until we added the file uploading support. To enable uploading of files, we had to change enctype of tag to multipart/form-data. Now, whenever we try to submit an article with multibyte characters, they become garbled after you receive them via $_POST. If we remove the form's enctype, then it works fine.

We have searched for all over the web for a php centric solution but without luck. There is an accept-charset attribute of tag but it does not work in IE. There is a solution for JSP at UTF-8 text is garbled when form is posted as multipart/form-data but no solution for PHP. So, please help!


回答1:


if you use PHP 5.4.x, setting mbstring.http_input from "auto" to "pass" may solve your problem.




回答2:


Reinstalling apache and recompile php fixed it for some ppl on linux.

I had the same on my localhost, but on the production server this does not happen. My local is WAMP, production is LAMP, everything has the same version.

So to me it works with these: CentOs 6.3, php 5.4, Apache 2.2.15

Btw, on my local, mb_detect_encoding() showes 'UTF-8' but the string is mess anyway.



来源:https://stackoverflow.com/questions/16083981/utf-8-text-is-garbled-when-form-is-posted-as-multipart-form-data-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!