in reply to upload image with cgi
Just check to make sure it's an image and write it to a binmode'ed file handle.
Untested Code:
my $filename = $cgi->param('uploaded_file'); my $type = $cgi->uploadInfo($filename)->{'Content-Type'}; #use the upload function if ($type eq 'image/jpeg') { open(IMAGE,">/image_dir/filename.jpg"); my $fh = $cgi->upload('uploaded_file'); binmode(IMAGE); while (<$fh>) { print IMAGE $_; } print '<img src="/image_dir/filename.jpg">'; } else { print 'Not a JPEG<br>'; }
|
|---|