Home  |  Linux  | Mysql  | PHP  | XML
From:Alexander Krasnorutsky Date:Fri Jun 19 19:25:14 2009
Subject:Re: Storing a file from a cgi parameter
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: krasnoroot@mail.ru.  

Navigate in group perl.beginners.cgi at sever nntp.perl.org
Previous Next


Your recent visits
sharing PHP sessions between web servers using NFS
Re: [PHP-INSTALL] Browser tries to download php file
Re: sequential value check
Re: Perl script to monitor memory usage on unix box


  
© No Copyright
You are free to use Anything
Site Maintained by Zareef Ahmed
Powered By PHP Consultants