问题
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