Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

sub uploadfile { &bytes; for ($i=1; $i<=5; $i++) { if ($q->param("file$i")) { $file = $q->param("file$i"); $format_left = format_size($left); if (($left - (length($file))) < 0) { &inerror("You are + out of space in your $format_limit limit, you only have $format_left + left."); } foreach $line (@badtypes) { if ($q->param("file$i") =~ /$line/) { &inerror("Invaild fil +e type"); } } $filename = $q->param("file$i"); $filename =~ s/.*[\/\\]//; open (OUTFILE,">$user{'site_id'}/$filename") || &error("Could +not create $filename: $!"); lock(OUTFILE); binmode OUTFILE; while ($bytesread=read($file,$buffer,2024)) { print OUTFILE $buffer; } close (OUTFILE); } } }
ok there is five upload fields, and when checking for errors I say: if (($left - (length($file))) < 0) { &inerror("You are out of space in your $format_limit limit, you only have $format_left left."); } Since this is like a file manager, say they have a space limit of 10mb but there was only 1mb left($left), and we find the length of the file and minus by what is left, and if its less than zero then there over it. Well what my trouble is, they well upload a script and it will be over the limit it wont say anything, but if they upload again while it is over the limit then it will show the erorr. It shouldn't be doing this. Any Ideas

2002-06-15 Edit by Corion : Changed title

Replies are listed 'Best First'.
Re: Perl Problem
by Anonymous Monk on Jun 15, 2002 at 04:50 UTC
    yeah, don't let them upload anything over the limit. Your logic is flawed. You read whatever they're throwing at you, even if it is a 100GB, and then you check the size, that's beyond crazy. Look into the HTTP spec, and further into CGI.pm, and even CGI::Safe and check for that before accepting anything. Doing this one file at a time is logically the easiest way to do it.

    Also, this is by no means a perl problem. You need to think a little harder when naming nodes (asking questions). There is a tutorial on asking questions in our Tutorials section. One of the most important things to keep in mind is reusability.

    How does your question benefit the community as well as you? By having a meaningfull node title so that others with the same question can find it quickly and easily ... perl question says nothing about your question.