SPUG: Re: retrieving image from form element
John Cokos
jcokos at ccs.net
Fri Jul 28 12:59:12 CDT 2000
How are you splitting the form data?
"multipart/form-data" is a special thingie that many stock
parsers won't be able to deal with.
If you're using CGI.pm, you should have to trouble.
ie:
my($size,$data,$total_size);
my $query = new CGI;
my $fullfilename = $query->param('image1');
my $filename = "whateveryouwant.jpg"; ## Should come from the form
### SLAM IT TO DISK ###
open (SAVE,">/full/path/to/some/directory/$filename") || die "Some error here";
while ($size = read($fullfilename,$data,1024)) {
print SAVE $data;
$total_size += $size;
}
close SAVE;
Of course, you'll want to do some file size and type checking
(so that noone can upload a virus.exe file that's named "mypic.jpg")
John========================================
John Cokos, President / CEO: iWeb Inc.
http://www.iwebsys.com
jcokos at ccs.net
========================================
----- Original Message -----
From: "marlin" <marlingreene at mindspring.com>
To: <spug-list at pm.org>
Sent: Friday, July 28, 2000 10:08 AM
Subject: SPUG: retrieving image from form element
> I'm using a file form element to point to a client side image that
> is sent to a server side Perl script. Here is the HTML...
>
> <FORM ACTION="/cgi-bin/handle_image.pl" METHOD="POST"
> ENCTYPE="multipart/form-data" >
> Select an image to send to database...must be .jpg format.<BR><BR>
> <INPUT TYPE="file" NAME="image1" ACCEPT="image/gif, image/jpeg"><BR><BR>
> <INPUT TYPE="Submit" NAME="submit" VALUE="Send Image">
> </FORM>
>
> On the receive side, if I use a typical print keys to see what came
> across I can see the data for the image...
>
> foreach $key (keys %in)
> {
> print "$key is $in{$key}<BR>"; #prints image data
> }
>
> However, if I print $in{image1} I get a "document contains no data" error.
>
> Can anyone tell me the correct way to capture the image data and save
> it to a file on the server side.
>
> Thanks in advance.
>
> Marlin Greene
>
> --
> 3 Hats Design
> INTERNET PRINT ILLUSTRATION
> 5201 15 Ave NW
> Suite 220
> Seattle, WA 98107
> 206.784.1641 phone
> 206.784.2231 fax
> marlin at 3hats.com
> http://www.3hats.com
>
> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
> POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
> Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
> Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
> For full traffic, use spug-list for LIST ; otherwise use spug-list-digest
> Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>
>
>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Subscriptions; Email to majordomo at pm.org: ACTION LIST EMAIL
Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
For full traffic, use spug-list for LIST ; otherwise use spug-list-digest
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
More information about the spug-list
mailing list