[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Re: <FILE> upload using Perl



Thanks Arun, Thaths, and Murali!

> CGI.pm is your friend.  See
> http://stein.cshl.org/WWW/software/CGI/cgi_docs.html#upload_caveats

I got the answer in the above mentioned Doc on CGI.pm :) CGI.pm is
indeed my friend now;)

I'm quoting a relevant para from there for the benefit of all list
members and the archives:

In order to take full advantage of the file upload facility you must use
the new multipart form encoding scheme. You can do this
either by calling startform() and specify an encoding type of
$CGI::MULTIPART or by using the new start_multipart_form()
method. If you don't use multipart encoding, then you'll be able to
retreive the name of the file selected by the remote user, but you
won't be able to access its contents. 

When the form is processed, you can retrieve the entered filename by
calling param(). 

       $filename = $query->param('uploaded_file');

---8<--snip a bit--8<--

The filename returned is also a file handle. You can read the contents
of the file using standard Perl file reading calls: 

        # Read a text file and print it out
        while (<$filename>) {
           print;
        }

        # Copy a binary file to somewhere safe
        open (OUTFILE,">>/usr/local/web/users/feedback");
        while ($bytesread=read($filename,$buffer,1024)) {
           print OUTFILE $buffer;
        }
       close $filename;

----8<-----------

 
WHAT I WAS DOING WRONG:

My FORM tag should actually have contained
"ENCTYPE=multipart/form-data". I hadn't put it there last time. Now
it's:

<FORM ACTION="MyPerlScript.pl"
METHOD=POST
ENCTYPE=multipart/form-data 
>


Arun said:
> But I couldn't get file upload to work on
> netscape-4.72 yesterday. Does the browser support it ?
   
I've seen it Work with Netscape 4.61 , and the documentation says its
supported from Netscape 2 onwards...

User-Agent: Mozilla/4.61 [en] (X11; I; Linux 2.2.12-20smp i686)


Regards,
Rohit

-- 
You teach best what you most need to learn.