ibjdt
Programmer
- Nov 25, 2002
- 63
problem1
i use the script below to allow image upload through my site. although i restrict the file size to 20Kb with
$CGI:OST_MAX = 1024 * 20;
i am able to upload any file size.
problem2
when the uploaded images are viewed on screen, i want them restricted to width=100 so i tried
but the resulting code is
does use Image::Size have to be in the script hdr? right now i have it just above the part of the script where it's used (as shown above).
thanks for the help.
i use the script below to allow image upload through my site. although i restrict the file size to 20Kb with
$CGI:OST_MAX = 1024 * 20;
i am able to upload any file size.
Code:
use File::Basename;
$CGI::POST_MAX = 1024 * 20;
$safe_filename_characters = "a-zA-Z0-9_.-";
@images = qw (image1 image2 image3 image4);
@types = qw (.jpeg .jpg .gif .bmp .png .art);
foreach $image(@images) {
if ($input{$image}) {
$filename = "$input{$image}";
if ( !$filename ) { $uploadError++; $ERROR_MSG .= "<img src=/graphics/icons/info.gif> <font color=red>Please check image file size (20Kb max): $input{$image}</font><br>"; }
( $name, $path, $extension ) = fileparse ( $filename, '\..*' );
$filename =~ s/[^$safe_filename_characters]//g;
$ERROR_MSG .= "<img src=/graphics/icons/info.gif> <font color=red>Image filename contains invalid characters: $input{$image}</font><br>" unless ( $filename =~ /^([$safe_filename_characters]+)$/ );
$uploadError++ unless ( $filename =~ /^([$safe_filename_characters]+)$/ );
$extOK = '';
foreach $type(@types) { if ($extension eq $type) { $extOK++; last; } }
$ERROR_MSG .= "<img src=/graphics/icons/info.gif> <font color=red>Invalid image file type: $input{$image}</font><br>" if (!$extOK);
$uploadError++ if (!$extOK);
}
}
problem2
when the uploaded images are viewed on screen, i want them restricted to width=100 so i tried
Code:
use Image::Size;
if ($image1) { ($width,$height) = imgsize($image1); $w="100" if ($width > 100); $IMAGE = "<a href=/ad_photos/$image1 target=_blank><img src=/ad_photos/$image1 width=$w border=0></a><p>"; }
but the resulting code is
Code:
<a href=/ad_photos/photoname.jpg target=_blank><img src=/ad_photos/photoname.jpg width= border=0></a><p>
does use Image::Size have to be in the script hdr? right now i have it just above the part of the script where it's used (as shown above).
thanks for the help.