Adding file size limit to picture-upload.pl
authorChris Nighswonger <cnighswonger@foundations.edu>
Wed, 26 Mar 2008 14:32:51 +0000 (10:32 -0400)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 1 Apr 2008 11:44:17 +0000 (06:44 -0500)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
koha-tmpl/intranet-tmpl/prog/en/modules/tools/picture-upload.tmpl
tools/picture-upload.pl

index 92e478c..11f781b 100644 (file)
@@ -51,6 +51,7 @@
                                         <!-- TMPL_ELSIF NAME="IMGEXISTS" -->this patron does not exist in the database.</li>
                                         <!-- TMPL_ELSIF NAME="MIMERR" -->the image format is unrecognized.</li>
                                         <!-- TMPL_ELSIF NAME="OPNERR" -->Koha was unable to open the image for reading.</li>
+                                        <!-- TMPL_ELSIF NAME="OVRSIZ" -->the image file is too big.</li>
                                         <!-- TMPL_ELSIF NAME="CRDFIL" -->the <!-- TMPL_VAR NAME="CRDFIL" --> is missing.</li>
                                         <!-- TMPL_ELSE -->of an unknown error. Please refer to the error log for more details.</li><!-- /TMPL_IF -->
                                     <!-- /TMPL_LOOP -->
index 144ca78..9d212ef 100755 (executable)
@@ -220,7 +220,15 @@ sub handle_file {
             } else {
                 $filename = $1 if ($source =~ /\/([^\/]+)$/);
             }
-            warn "\$filename=$filename";
+            warn "$filename is " . length($imgfile) . " bytes";
+            if (length($imgfile) > 100000) {
+                warn "$filename is TOO BIG!!! I refuse to beleagur my database with that much data. Try reducing the pixel dimensions and I\'ll reconsider.";
+                $filerrors{'OVRSIZ'} = 1;
+                push my @filerrors, \%filerrors;
+               push @{ $count{filenames} }, { filerrors => \@filerrors, source => $filename, cardnumber => $cardnumber };
+                $template->param( ERRORS => 1 );
+                return %count;
+            }
             my $mimetype = $mimemap->{lc ($1)} if $filename =~ m/\.([^.]+)$/i;
             warn "$filename is mimetype \"$mimetype\"" if $DEBUG;
             my $dberror = PutPatronImage($cardnumber,$mimetype, $imgfile) if $mimetype;