[cgiapp] file uploads and encodings

Joshua Miller unrtst at gmail.com
Mon Oct 4 17:44:43 EDT 2010


On Mon, Oct 4, 2010 at 5:33 PM, Michael Peters <mpeters at plusthree.com> wrote:
> On 10/04/2010 05:13 PM, ĵohn sayļør wrote:
>
>> i think you have to do this programmatically by examining the characters
>> in the file. there may be libraries to do this already somewhere, but i
>> have exerted no effort to find them.
>
> It's not 100% (it can't be when you don't know the encoding) but you can
> use something like Encode::Guess or Text::GuessEncoding.

Still not a 100% solution, but you can also check the BOM:

http://search.cpan.org/~mattlaw/File-BOM-0.14/lib/File/BOM.pm

If it's there, use it... else, move on to guessing, and fall back to
utf8 (or ascii, and barf all over if something is out of range).
--
Josh I.


More information about the cgiapp mailing list