Re: File uploading
On Fri, 18 Jul 2003 at 12:03, Mike Harrison opined: MH:I have a perl program that allows a user to upload a file (either .jpg or MH:.gif) to the server, and returns a message if it exceeds a specified size MH:(in my case 100kB). Currently (and don't laugh - I am new to perl), I go MH:through the motions of uploading the file in 1024-byte blocks (in binary MH:mode), and increment a counter with each block. If the counter exceeds 100 MH:(i.e. greater than 100kB), then it exits the loop, displays a warning MH:message and deletes the file. MH: MH:I am sure there would have to be an easier and more efficient way of doing MH:this - that is, somehow finding out how large the file is without having to MH:download it first. MH: MH:Does perl have a module that can check the size of the file? And for that MH:matter, its type (.jpg, .gif etc.)? hi mike - CGI provides a way to indicate if an form post exceeds a pre-determined size limit. it's the $CGI::POST_MAX variable, and if you wanted to limit uploads to 100kbytes (for example), you'd do something like this: use CGI; $CGI::POST_MAX = 100 * 1024; my $cgi = new CGI; if ($cgi-cgi_error) { # alert the user their post exceeded the limit exit(); } you can find out more information by reading perldoc CGI -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File uploading
Thanks fliptop. The $CGI::POST_MAX variable worked well. What if I now want to upload 2 files. The first can be up to 100k in size and the second up to 80k in size? That is pretty much the way I have it set up at the moment... Or should I admit defeat at this stage and allow 2 files to be uploaded that have a combined size of 180k maximum? Is there a way of knowing the file size after say: my @pic_filenames = ($query-param('picfile1'), $query-param('picfile2')); where picfile1 picfile2 are defined from the multipart/form-data post. Can I then check the size along the lines of (where FILESIZE is some function to get the size of a file)... if (( FILESIZE (@pic_filenames[0]) 1024*100) || (FILESIZE (@pic_filenames[1]) 1024*80)) { # print error message here } Thanks in advance, Mike. On Fri, 18 Jul 2003 at 12:03, Mike Harrison opined: MH:I have a perl program that allows a user to upload a file (either .jpg or MH:.gif) to the server, and returns a message if it exceeds a specified size MH:(in my case 100kB). Currently (and don't laugh - I am new to perl), I go MH:through the motions of uploading the file in 1024-byte blocks (in binary MH:mode), and increment a counter with each block. If the counter exceeds 100 MH:(i.e. greater than 100kB), then it exits the loop, displays a warning MH:message and deletes the file. MH: MH:I am sure there would have to be an easier and more efficient way of doing MH:this - that is, somehow finding out how large the file is without having to MH:download it first. MH: MH:Does perl have a module that can check the size of the file? And for that MH:matter, its type (.jpg, .gif etc.)? hi mike - CGI provides a way to indicate if an form post exceeds a pre-determined size limit. it's the $CGI::POST_MAX variable, and if you wanted to limit uploads to 100kbytes (for example), you'd do something like this: use CGI; $CGI::POST_MAX = 100 * 1024; my $cgi = new CGI; if ($cgi-cgi_error) { # alert the user their post exceeded the limit exit(); } you can find out more information by reading perldoc CGI -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File uploading
On Fri, 18 Jul 2003 at 23:46, Mike opined: M:What if I now want to upload 2 files. The first can be up to 100k in size M:and the second up to 80k in size? That is pretty much the way I have it set M:up at the moment... M: M:Or should I admit defeat at this stage and allow 2 files to be uploaded that M:have a combined size of 180k maximum? since $CGI::POST_MAX examines the overall size of the entire post, there wouldn't be a way to use it to determine sizes of multiple files individually. in this case, you'd have to split the uploads into 2 forms, or use one of the other methods that were suggested to examine each file on its own. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: File uploading
Just a warning. This method doesn't work right under Windows. The file is fully uploaded, then it is tested if the max size of the file is overdone. If the file size is 10 GB, the file is fully uploaded first, then... doesn't matter ... but the program will work, and after it finish uploading, it tells the visitor that the file is too big. Teddy, Teddy's Center: http://teddy.fcc.ro/ Email: [EMAIL PROTECTED] - Original Message - From: fliptop [EMAIL PROTECTED] To: Mike Harrison [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Sent: Friday, July 18, 2003 4:19 PM Subject: Re: File uploading On Fri, 18 Jul 2003 at 12:03, Mike Harrison opined: MH:I have a perl program that allows a user to upload a file (either .jpg or MH:.gif) to the server, and returns a message if it exceeds a specified size MH:(in my case 100kB). Currently (and don't laugh - I am new to perl), I go MH:through the motions of uploading the file in 1024-byte blocks (in binary MH:mode), and increment a counter with each block. If the counter exceeds 100 MH:(i.e. greater than 100kB), then it exits the loop, displays a warning MH:message and deletes the file. MH: MH:I am sure there would have to be an easier and more efficient way of doing MH:this - that is, somehow finding out how large the file is without having to MH:download it first. MH: MH:Does perl have a module that can check the size of the file? And for that MH:matter, its type (.jpg, .gif etc.)? hi mike - CGI provides a way to indicate if an form post exceeds a pre-determined size limit. it's the $CGI::POST_MAX variable, and if you wanted to limit uploads to 100kbytes (for example), you'd do something like this: use CGI; $CGI::POST_MAX = 100 * 1024; my $cgi = new CGI; if ($cgi-cgi_error) { # alert the user their post exceeded the limit exit(); } you can find out more information by reading perldoc CGI -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
File uploading
Hello, I have a perl program that allows a user to upload a file (either .jpg or .gif) to the server, and returns a message if it exceeds a specified size (in my case 100kB). Currently (and don't laugh - I am new to perl), I go through the motions of uploading the file in 1024-byte blocks (in binary mode), and increment a counter with each block. If the counter exceeds 100 (i.e. greater than 100kB), then it exits the loop, displays a warning message and deletes the file. I am sure there would have to be an easier and more efficient way of doing this - that is, somehow finding out how large the file is without having to download it first. Does perl have a module that can check the size of the file? And for that matter, its type (.jpg, .gif etc.)? Thanks in advance, Mike.
file uploading
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 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: file uploading
--- 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]