Search code examples
phpencodingcharacter-encodingphp-5.4

PHP 5.4 multipart/form-data UTF-8 encoding


I'm having problem with UTF-8 encoding while posting form data as "multipart/form-data", without multipart/form-data everything works well. But since I have to upload files on same post, I need to use multipart/form-data.

Problem started after upgrading from PHP 5.3.x to PHP 5.4.4-14 (bundled with Debian Wheezy), same scripts works well with PHP 5.3 test server.

  • All of my documents are saved in UTF-8 and has <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> tags.
  • I tested with different browsers on different computers
  • mb_detect_encoding() detects posted string as UTF-8
  • I tried AddDefaultCharset utf-8 for Apache configuration.

Here you can test my scripts, you can copy/paste following string with Turkish characters (ex. string: öçşipğopüp )

http://sa.chelona.com.tr/haber-ekle.html

I also found related question at UTF-8 text is garbled when form is posted as multipart/form-data in PHP but it recommends re-installing apache/php and that's not possible for my situation. Is this a known PHP/Apache bug?


Solution

  • I'm writing this to answer my own question... I hope it will help somebody else...

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