From your input (
not yet woven in ikegami's last post, working on it) I constructed this variation, which should replicate in a simplified form, what the routine in my more complex CGI::Application script will be like:
#!/usr/bin/perl -COE
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use utf8;
use Encode;
my $cgi = new CGI;
my $formtext = decode("utf8", $cgi->param("formtext") ); # this may be
+ abc or contain chinese
my $filename = $cgi->param('file');
my $fh_in = $cgi->upload('file');
open(my $fh_out, '>', "/var/www/clipland/www.clipland.com/$filename")
+or die $!;
binmode $fh_in;
binmode $fh_out;
local $/ = \4096; # Don't wait to find "\n"
while (<$fh_in>) {
print $fh_out $_;
}
$cgi->header(-charset => 'utf-8');
print $cgi->header();
print "$filename has been successfully uploaded... Now some umlauts: ä
+öü";
1. It only uses the -COE switch for Stdoutput and Stderr. (using -CS will give the error, despite ikegami's fixes)
and as Juerd pointed out: it's safer.
2. I do not switch utf8 on for the Stdinput, thus I need to manually decode form data from text fields - right?
Is this OK? Anything I've overseen?
BTW: no kidding? I have to differentiate between text and binary data?? A great relief to hear that utf8 text files are also binary data... ;-)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.