--- "Greg D." <[EMAIL PROTECTED]> wrote: > Hello, > > I was wondering if anyone knew the best way to upload a file and then > populate the text area with the text file you just selected. Is there any > way to do that with perl and cgi instead of having to use javascript? > Or if that is not possible in perl and cgi is there a way to save the message > i select so that it will be referred to as "message" . > i have the code to upload the file which is: > > <form method="post" enctype="multipart/form-data" action="form.cgi"> > <input type="file" name="message" size=55> > > thanks for any help. > Greg
Untested: #!/usr/bin/perl -wT use strict; use HTML::Entities; use CGI qw/:standard/; CGI::POST_MAX = 1024 * 1024; # limit posts to 1 Meg # $file is also a filehandle my $file = param( 'message' ); my $message; { local $/; # slurp mode; binmode $file; $message = <$file>; } # must encode characters that will screw with HTML $message = encode_entities( $message ); At this point, $message should have the data you need, in a form safe for populating the text area. Of course, I just typed this into my mail client without proofreading, so you'll want to see the following for more information: perldoc CGI perldoc HTML::Entities You want to use the CGI::upload method (instead of the param call) if you have CGI::VERSION > 2.47. You can also call: # is $file the handle or the name? I can never remember my $type = uploadInfo($file)->{'Content-Type'}; to get the content type, if you wish to restrict them. This, of course, is a convenience feature and not really a security feature as this is easily spoofed. Cheers, Curtis "Ovid" Poe ===== "Ovid" on http://www.perlmonks.org/ Someone asked me how to count to 10 in Perl: push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//; shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]