Storing a file from a cgi parameter

[email protected] (J Alejandro Ceballos Z) Tue, 16 Jun 2009 21:29:47 -0500
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
I am trying to store a file in the temp directory.

It creates the desired file, but with size 0.

The files are videos sent via CGI. I tried with the upload function,  
but it did not work too.

Would you please give me some direction about what I am doing wrong or  
what should I do in order to make it work?

Thank you.



# Load system modules (strict disabled in order to prevent conflict)
use CGI;
# use strict;

# Create CGI
my $cgi_this = new CGI;
my $file_file = $cgi_this->param('sbvideo_file') || 0;

# retrieve original name and change it
if ($file_file =~ /(.+)\.(\w+)$/)
    { ($str_filename,$str_fileext) = ($1,$2); }
$str_filename = $$ . '.'. $str_fileext;

# this line does not work, sends error on hash content type key
#  $str_filetype = $cgi_this->uploadInfo($file_file)->{'Content-Type'};

# store file (that does not work)
       if (open (hFILE, ">~/tmp/$str_filename"))
         {
         binmode hFILE;
         while (<$file_file>)
           { print hFILE $_; }
         close (hFILE);
         }

# store file 2nd option (and this one neither)
       if (open (hFILE, ">~/tmp/$str_filename"))
         {
         binmode hFILE;
         while (read($file_file,$str_buffer,1024))
           { print hFILE $str_buffer; }
         close (hFILE);
         }




Atentamente,

J. Alejandro Ceballos Z.

    w: http://alejandro.ceballos.info
    e: [email protected]
    m: +52 (33) 1411.6079