in reply to Upload a file from a web form

$filename is not a filehandle. The "param()" method returns the file name but not an opened filehandle to it. This file name cannot be opened directly with an "open()" as the file does not exist on your filesystem, it is the file name on the client host.

If your CGI.pm does not handle the "upload()" method you can upgrade it (with perl -MCPAN -e 'install CGI') or, if you don't have root access to the webserver, grab an updated CGI.pm module file and put it in a directory on your webserver and load it in your scripts with:
use lib "/where/is/your/cgi/module"; use CGI;
That should load this newest module instead of the system default module.

update: cfreak is right and i'm absolutely wrong. I checked the doc, and param() on an upload field returns a filename that is also a filehandle. Thanks cfreak.

Replies are listed 'Best First'.
Re: Re: Upload a file from a web form
by cfreak (Chaplain) on Jul 09, 2003 at 14:19 UTC

    Not, true. If your param is an uploaded file field it works as both the filename or the filehandle depending on the context you use it in. The upload() method was added later to be less confusing.

    Lobster Aliens Are attacking the world!
Re: Re: Upload a file from a web form
by bodmin (Sexton) on Jul 09, 2003 at 14:47 UTC
    Tried that and get the following error:

    Parameter to use lib must be directory, not file

      Of course, in my "code", you should understand the "/where/is/your/cgi/module" string as the directory name in which you have CGI.pm and not the full path name to the CGI.pm file (/where/is/your/cgi/module/CGI.pm) ...
        Tried that and got "Bad header=BEGIN failed--compilation abor"