On Tue, 2009-06-16 at 21:29 -0500, J Alejandro Ceballos Z wrote:
> 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);
You can try use the "$cgi_this->upload" method to retrieve the
filehandle. There is a standard module named "File::Temp" for generating
names for temporary files.
--
Alexander Krasnorutsky.
Email: [email protected].
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/