[Perl] Uploading files

Gaal Yahas gaal at forum2.org
Thu Aug 1 01:43:36 PDT 2002

On Thu, Aug 01, 2002 at 11:17:29AM +0200, Fischer Michael wrote:
> Hi,
> I want that cgi-script on server will on demand upload text-file from user's computer.
> ...
> After submit I am getting filehandle from $q->param("uploaded_file")...
> The question is how I can use this handle to read this file more then once?
> How I can read this file (from user's computer) in another cgi script?

Is it a good idea in your application to transfer the file several times
over the network? Consider caching the file on the server instead. This
means you'll have to do some occasional housecleaning and think about
privacy a little more than if the file were not kept on the server. You
also need to figure out a way to communicate the local filename between
your CGIs, which is in a way what your original question boils down to.

The answer to the question, "how do two CGIs communicate?" has no
standard answer. CGIs are stateless, and are invoked by the user hitting
on the server whenever the user feels like it. What this means is that
you will have to roll your own solution according to the kind of
cooperation you want from your CGIs.

*How* is the second CGI called? Is it the ACTION result, for example,
of a form submitted by the user, a form that the first script had
generated? In that case, you're in luck: you pass your information
(filename in my suggestion, but see below) as a hidden CGI parameter
to script #2. If that's not how it works, you'll need to be more

If you must pass filehandles, there's no elegant or even remotely
simple way of doing it. You might write an independet server process
with which the CGIs negotiate the open filehandles; I don't remember
where but I think Mark-Jason Dominus once wrote a bit on how to do this
in Perl. Good luck with that, if you tackle it. Tell us how you did :)

Gaal Yahas <gaal at forum2.org>

More information about the Perl mailing list