Javascript-use a form to upload files. The Chinese field of multipart/form-data is garbled. How can this problem be solved?

Source: Internet
Author: User
Happy New Year !! I used the yii2 form. Previously, my form did not contain the Upload file & amp; lt; inputtype & quot; file & quot; & amp; gt;, and the Chinese field is normal, however, after the file is uploaded, set & #039; enctype & #039; & amp; gt; & #039; multipartform-data & #039 ;, then there is a problem with the upload. I...Happy New Year !!

I used the yii2 form. Previously, my form did not contain an uploaded file.The Chinese field is normal, but after the file is uploaded'enctype' => 'multipart/form-data'And then the upload fails. I found that$_POSTAll Chinese fields in are garbled, and the Chinese characters stored in the database are also garbled. Useaccept-charsetSetting character sets does not work either. How can this problem be solved?

Reply content:Happy New Year !!

I used the yii2 form. Previously, my form did not contain an uploaded file.The Chinese field is normal, but after the file is uploaded'enctype' => 'multipart/form-data'And then the upload fails. I found that$_POSTAll Chinese fields in are garbled, and the Chinese characters stored in the database are also garbled. Useaccept-charsetSetting character sets does not work either. How can this problem be solved?

You can do this:

Enctype = "multipart/form-data; charsets = UTF-8"

Other approaches:

  1. It is best to use the error_log (print_r ($ _ POST, 1) output to see it, without the built-in debuger.

  2. Php. ini: default_charset = "UTF-8" can be modified"

  3. You can modify. htaccess: AddCharset UTF-8. php

Your page is directly returned after submission$POST?
First, set the form page and display$_POSTTo the same character encoding, such

 
  

We recommend that you upload files to a separate form.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.