CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Intermediate:
Upload Files Size Check



Nov 8, 2001, 1:34 PM

Post #1 of 3 (625 views)
Upload Files Size Check Can't Post

I have created a script using that allows an upload to a directory. I have attached the file to this message so you can read through it. I was wondering how you could set an upload file size limit on the file being uploaded. I going to use this script in a program and would like a maximum of 20kb to be uploaded per upload, if the upload is more than 20kb I would like the program to die, and cancel the upload.

Also how would I set which files I would like to have uploaded e.g. just .html, or just .jpg.

Any help for these problems would be most appreciate.

Many Regards,
Ben Chivers


Nov 8, 2001, 2:41 PM

Post #2 of 3 (622 views)
Re: Upload Files Size Check [In reply to] Can't Post

Ben, to set which files you want uploaded just include an extention to your filename as follows:

if($filepath =~ s!^.*(\\|\/)('*.html')!!) { print $_; }

To set a limit on the file being uploaded, try this:

open(FILE, ">$file") or die $!;
use Fcntl;
my $bytes = "";
my $buffer = "";
my $size = 0;
while (my $bytes = read($file, my $buffer, 1024)) {
binmode FILE;
$size += $bytes;
if($size == '?') {
print FILE $buffer;
close (FILE);


Nov 10, 2001, 6:52 AM

Post #3 of 3 (612 views)
Re: Upload Files Size Check [In reply to] Can't Post

$CGI::POST_MAX and $CGI::DISABLE_UPLOADS should help you out.

There is just one small problem. the post_max varaible coulds the data transfererd from the browser, which includes the parameter names and values.

Yet an Other Perl Programmer

Find out more about programming


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives