开发者

How do I upload file using CGI APPLICATION

开发者 https://www.devze.com 2023-01-25 19:24 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号