Hi,

I have a webapplication in perl which uses UTF-8 everywhere. At the top of my scripts is "use open ':utf8';" and "use open ':std';" which makes everything work correctly. Without these lines 'special' characters that come f.e. from the database turn into question marks in the browser.

Recently I added a file upload option to the application, but when I try to upload, I get tons of errors in my log complaining about bad utf-8:

[Wed Aug 15 20:55:42 2007] [error] [client 127.0.0.1] [Wed Aug 15 20:5 +5:42 2007] script.pl: Malformed UTF-8 character (unexpected continuat +ion byte 0x99, with no preceding start byte) in index at (eval 44) li +ne 15., referer: http://localhost/formtest.html [Wed Aug 15 20:55:42 2007] [error] [client 127.0.0.1] [Wed Aug 15 20:5 +5:42 2007] script.pl: Malformed UTF-8 character (byte 0xff) in index +at (eval 44) line 15., referer: http://localhost/formtest.html [Wed Aug 15 20:55:42 2007] [error] [client 127.0.0.1] [Wed Aug 15 20:5 +5:42 2007] script.pl: Malformed UTF-8 character (unexpected non-conti +nuation byte 0x0d, immediately after start byte 0xd9) in index at (ev +al 44) line 15., referer: http://localhost/formtest.html [Wed Aug 15 20:55:42 2007] [error] [client 127.0.0.1] [Wed Aug 15 20:5 +5:42 2007] script.pl: Wide character in print at (eval 38) line 85., +referer: http://localhost/formtest.html

The uploaded file is totally corrupt when saved (btw I use CGI.pm). It seems that the file is not sent as UTF-8 for some unknown reason; I do specify UTF-8 charset in my forms and html, and the http headers confirm that it's supposed to be UTF-8.

When I remove the two "use open" lines from my perl script, the uploads go fine, but then the special chars are screwed in my app. It's a multi lingual site so correct display of special chars like c cedille and umlauts is essential. Hence the choice for UTF-8.

I'm caught between a rock and a hard place. How do I get out?


In reply to UTF-8 woes with file upload by Farenji

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.