How do I upload file using CGI APPLICATION
Hi I am trying to upload image file using perl cgi-application. Not sure what I am doing wrong - but an em开发者_运维技巧pty image file (with the right name) gets saved.
my $picture = $self->query->param('picture') ;
my $buffer; my $bytesread;open (OUTFILE, ">>$user_dir/profile_picture/$picture");
while ($bytesread = read($picture, $buffer, 1024)) { print OUTFILE $buffer; }Read the " CREATING A FILE UPLOAD FIELD" section of CGI.pm documentation. There you will see that the upload method will return a filehandle.
my $fh = $self->query->upload('picture');
my $buffer; my $bytesread;
while ($bytesread = read($fh, $buffer, 1024)) {
...
}
Don't forget your HTML form element also needs to specify enctype='multipart/mixed', otherwise the upload filestream doesn't get sent.
精彩评论