my $datafile = $CGI->param('datafile');

On Thu, 2002-10-03 at 23:02, Erik Price wrote:
> A quick question --
> 
> Can anyone explain the "theory" of file uploads via browser to me?  I 
> have a MS Excel spreadsheet that needs to get uploaded to a server 
> periodically and parsed.  I've written a script to do this on the 
> localhost.  But I've been asked to make this available as a 
> browser-based upload, so that users can upload the spreadsheet and it 
> will get parsed when it is uploaded.  The details I can research, but 
> the underlying concept -- anyone have a rough outline of the process 
> they can describe to me?

John's valid concerns aside, here's the basic ide using CGI.pm. Yes it's
a module, however it has been distrubited with the Perl core for quite a
while now, so you probably have access to it.

In your CGI you will need to make a CGI object. Read the documentation,
but commonly its:
use CGI qw(:standard);
our $CGI = new CGI;

Then in the subroutine where you read the file:
        my $datafile = $CGI->param('datafile');
        while (<$datafile>) {
                # some stuff
        } # while

That's pretty much all there is to it on the server side. I've always
found the docs a little confusing on how to get the usuable filehandle,
but the above always works for me.

One other important consideration though is that the form presented to
the user must be multipart. So your form tag in your web page should
look something like:
<FORM ACTION="http://$ENV{HTTP_HOST}/cgi-bin/foo.cgi";
    enctype="multipart/form-data" METHOD="post">

HTH!

Sean Quinlan
[EMAIL PROTECTED]
617-884-4338

Churchill's Commentary on Man:
        Man will occasionally stumble over the truth, but most of the
time he will pick himself up and continue on.



_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to