http://www.perlmonks.org?node_id=18438

Punto has asked for the wisdom of the Perl Monks concerning the following question:

Hi.. can anyone point me to an example on handling file uploads (on a CGI script)?

Thanks..

Replies are listed 'Best First'.
Re: handling file uploads.
by wonko (Pilgrim) on Jun 16, 2000 at 15:32 UTC
    I asked the same thing about a week ago, check that thread uploading a file

    /wonko

      question about the code on that thread: is there any way to find out the name of the file that's being uploaded?

      Thanks..

Re: handling file uploads.
by lhoward (Vicar) on Jun 16, 2000 at 14:31 UTC
    See the CGI modle documentation.
    To be safe, use the upload() function (new in version 2.47). When called with the name of an upload field, upload() returns a filehandle, or undef if the parameter is not a valid filehandle.
    $fh = $query->upload('uploaded_file');
Re: handling file uploads.
by cbraga (Pilgrim) on Jun 19, 2000 at 06:55 UTC
    The excellent Apache Week has a great feature on publishing data with put, including the full source code of a perl script that handles file uploads. Check it out here.
Re: handling file uploads.
by Punto (Scribe) on Jun 19, 2000 at 06:14 UTC
    Ok, I have this new problem now:

    I use:

    $filename = $query->param('uploaded_file');
    And $filename is always empty. I know the file is being transmitted by the browser because I used netcat to see the request..

    Any ideas? thanks..

      Your input field must be named 'uploaded_file' and you really ought to use the CGI::upload() method instead of CGI::param() there.

      Probably just a typo, happens to me all the time.

      CGI::upload() was added in a newer version of CGI, so you might want to upgrade.

        Your input field must be named 'uploaded_file' and you really ought to use the CGI::upload() method instead of CGI::param() there.

        I know.. but when I use upload() I get "Undefined subroutine CGI::upload".

        Probably just a typo, happens to me all the time.

        I checked the spellig too.. :)