#!/usr/bin/perl -w use strict; use CGI::Carp qw( fatalsToBrowser ); use CGI ':standard'; use Image::Size; use Image::Magick; my (@inx,$ac,$ar,@filename,@array_reference,@working_filename,$array_begin,$array_end,$in,$save_file); my $image = Image::Magick->new; my $upload_dir = "../../pics"; $CGI::POST_MAX = 2048; binmode(STDIN); @inx = ; #my ($ac,$ar); $ac = 0; $ar = 0; foreach (@inx) { delete @inx[$ac] if $_ =~ /^Content-Type: application\/octet-stream/; $ac++; } $ac = 0; # Define individual uploaded files within the array foreach (@inx) { if ($_ =~ /^Content-Type/) { $filename[$ar] = $inx[$ac-1]; $array_reference[$ar] = $ac; @working_filename = split /filename=/, $filename[$ar]; @working_filename = split /"/, $working_filename[1]; # " @working_filename = split /\\/, $working_filename[1]; $filename[$ar] = pop @working_filename; $ar++; } $ac++; } $ac = 0; $ar = 0; print "content-type: text/html\n\n"; # Pull files from the array and write to disk foreach (@filename) { $array_begin = $array_reference[$ac] + 2; $array_begin = 0 if $array_begin < 0; $array_end = $array_reference[$ac+1] - 3; $array_end = ($#inx) if $array_end < 0; for (my $ii = $array_begin; $ii <= $array_end; $ii++) { $in .= $inx[$ii]; } $in = substr($in,0,length($in) - 2); $save_file = "$upload_dir/$_"; # get the image size my( $width, $height ) = imgsize($save_file); # resize image files here $image->read('$save_file'); $image->Set( Gravity => 'Center' ); $image->Resize( geometry => '180x168' ); $image->Extent( geometry => '180x168' ); my $n_image = $image->Write( '$save_file' ); # get the new image size here and save the new file size to dir my( $width2, $height2 ) = imgsize($n_image); # I am printing here to make sure the photo has been resizedm but it is not working print "
2-$width2, $height2
"; open(FF,">$save_file") or die $!; binmode(FF); print FF $in; close(FF); $in = ""; $ac++; print "Uploaded file $save_file
"; print ""; }