Forum Moderators: phranque

Message Too Old, No Replies

Users unable to upload larger images

         

csdude55

5:59 pm on Mar 22, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



For YEARS I've had people email and say that they can't get a photo to upload, but they never give me any more details >:-(

But for the first time ever, yesterday someone emailed and actually included the picture they were trying to upload! The photo was 4.4MB in size.

On my end, the photo is uploaded to a /cache/ directory, then resized and copied to its permanent location.

I first looked at php.ini. post_max_size is set to 50M, and upload_max_filesize is 50M. My uploads are done in Perl, anyway, but I wanted to make sure.

I looked in the Perl script that's mostly used for upload (that I wrote maybe 8 years ago), and the code there is pretty basic:

# the variables are set earlier, this is just for your reference to see how it's done
$old_pic = upload($_GET{'picID'});

open PIC, ">$cache_path/$pic";
binmode (PIC);
while ($bytes = read($old_pic,$data,16384)) { print PIC $data; }
close PIC;


Any other suggestions on where I might be inadvertently limiting the file upload size?

phranque

10:44 pm on Mar 22, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I first looked at php.ini. post_max_size is set to 50M, and upload_max_filesize is 50M. My uploads are done in Perl, anyway, but I wanted to make sure.

perl has a similar global variable setting which you may want to explore - $CGI::POST_MAX

https://metacpan.org/pod/CGI#$CGI::POST_MAX

Any other suggestions on where I might be inadvertently limiting the file upload size?

have you checked the web server error log file for clues?

csdude55

12:33 am on Mar 23, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



perl has a similar global variable setting which you may want to explore - $CGI::POST_MAX

Are you saying that this is a default setting somewhere, or just something that I may have added in the past? I looked but don't see it anywhere.

I also searched all of my scripts for "-s", knowing that I would normally use that to return the filesize. I didn't find anything that would have caused this problem, though.

have you checked the web server error log file for clues?

Yup, but no luck.

I've also tried uploading the exact same 4.4MB file on my end using the same script they would have used, but it worked just fine. So now I suspect that the issue isn't just the file size, but the time it takes them to get it to upload.

I found the "Timeout" setting in Apache, which I have set to 60 (assuming that's in seconds). I'll try bumping that up tonight, when I can rebuild Apache without disruption. Any other ideas of anything else that might cause a timeout?

Brett_Tabke

11:25 pm on May 25, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



What module are you using for your CGI variables? Or is the script hand processing them?

If you are using CGI that is what Phranque was referring too. Look for "use CGI" in the script.

If you are accidently "doing it by hand", there has be a limit to the number of bytes that can be uploaded, or you would be open to easy Ddos attacks from people flooding the script and causing buffer overflows.

What is the "upload" routine?

csdude55

3:17 am on May 26, 2022 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Oh, I see. The script is hand written, but I do use CGI for upload().

What's the default for $CGI::POST_MAX? The docs implied that there's no limit unless you explicitly set it.

[metacpan.org...]

engine

8:29 am on May 26, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Is that upload limit based on compressed files or uncompressed files? For example jpeg compression is about 10:1, and uncompressed files could easily take them over the 50mb limit.

Brett_Tabke

11:21 am on May 26, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month




Throw this in near the top of your script and then try to upload a large file. See if it throws an error:

use CGI::Carp qw (fatalsToBrowser);

also, I've not used CGI for uploads before, but the 16384 looks interesting. What does that mean?
read($old_pic,$data,16384)

Brett_Tabke

2:23 pm on May 29, 2022 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



just fyi - I have used CGI for uploads before...still do in fact.


# $SAVE_DIRECTORY = where to save file

sub GetUpload {
$| = 1;
use CGI qw(:standard);
$query = new CGI;

foreach $key (sort {$a <=> $b} $query->param()) {

#print "k: $key v: ". $query->param($key) . "<br>\n";
next if ($key =~ /^\s*$/);
next if ($query->param($key) =~ /^\s*$/);
next if ($key !~ /^file-to-upload-(\d+)$/);
$Number = $1;

if ($query->param($key) =~ /([^\/\\]+)$/) {
$Filename = $1;
$Filename =~ s/^\.+//;
$File_Handle = $query->param($key);
return(8);# if (!$ALLOW_INDEX && $Filename =~ /^index/i) {
} else {
$FILENAME_IN_QUESTION = $query->param($key);
return(7);# no filename
}

if (!open(OUTFILE, ">$SAVE_DIRECTORY\/$Filename")) {
chmod(0777, "$SAVE_DIRECTORY\/$Filename") if $operatingsystem eq "unix";

return(6); #print "There was an error opening the Output File\n";
}

undef $BytesRead;
undef $Buffer;
while ($Bytes = read($File_Handle,$Buffer,1024)) {
$BytesRead += $Bytes;
print OUTFILE $Buffer;
}
push(@Files_Written, "$SAVE_DIRECTORY\/$Filename");
$TOTAL_BYTES += $BytesRead;
$Confirmation{$File_Handle} = $BytesRead;
close($File_Handle);
close(OUTFILE);
}

$FILES_UPLOADED = scalar(keys(%Confirmation));

if ($TOTAL_BYTES > $MAXIMUM_UPLOAD && $MAXIMUM_UPLOAD > 0) {
foreach $File (@Files_Written) {
unlink $File;
}
return(5); #<TITLE>Error: Limit Reached</TITLE>
}
}