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]