38673

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

Question:

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 <a href="https://stackoverflow.com/questions/546365/utf-8-text-is-garbled-when-form-is-posted-as-multipart-form-data" rel="nofollow">UTF-8 text is garbled when form is posted as multipart/form-data</a> but no solution for PHP. So, please help!

Answer1:

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

Answer2:

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.

Recommend

  • Using CFile::typeUnicode
  • php remove “empty” values in array
  • Replace accented characters using gsub
  • Open Source libraries for PDF to image conversion [duplicate]
  • Japanese/Korean characters encoding issue on IIS7 windows 2008 server
  • Thread swaps in and out automatically without any yield or sleep
  • Yii: any way to save the images in compressed form?
  • How to read data from a text file if the file location is not known in c#?
  • View/Download Pdf Files in React - Router 4
  • How to remove last utf8 char of a python string
  • SQL append distinct values from two columns and two tables
  • Encode string to match encoded form field name in PHP POST array
  • HALF_PTR Windows data type
  • Syntax error near unexpected token 'elif'
  • Passing parameter through “window.location.href”
  • array_search() in Session Array
  • custom string delimiters stringtemplate-4
  • read values from form post in jquery or javascript
  • apply a javascript function to draggable copy
  • Consuming a WCF service in a Java Client using wsHttpBinding
  • JQuery .html() remove line break on IE 8
  • Validate jQuery plugin, field not required
  • Exception gevent.hub.LoopExit: LoopExit('This operation would block forever',)
  • How to make JSON.NET deserialize to Microsoft Date Time?
  • Button click event not firing in jQuery
  • Display images in Django
  • chrome.tabs.executeScript only fires when the Developer Console is open
  • With Hadoop, can I create a tasktracker on a machine that isn't running a datanode?
  • Word Open XML Mail Merge
  • JSON response opens as a file, but I can't access it with JavaScript
  • Regex thinks I'm nesting, but I'm not
  • What is the “return” in scheme?
  • req.body is undefined - nodejs
  • When should I choose bucket sort over other sorting algorithms?
  • How to get icons for entities from eclipse?
  • How to disable jQuery.jplayer autoplay?
  • embed rChart in Markdown
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app