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

Fellow Monks,
I was wondering how I can verify and upload a file to my server from client computers. I have a form that uses:

<INPUT type="file" name="File1">

So that the user can specify a file on their machine. I want to verify that the file exists via my CGI script and if possible, verify that the file is an image, and the size of the image. I would like to put the images in the "images" folder on my server.

Thank You.

Replies are listed 'Best First'.
Re: Uploading Files?
by Taulmarill (Deacon) on Dec 11, 2003 at 16:05 UTC
    your question has been answered before, look here.
Re: Uploading Files?
by davido (Cardinal) on Dec 11, 2003 at 18:01 UTC
    The POD for CGI.pm has a pretty good description of handling file uploads. Be sure to read it (and use CGI;). To that I might add that you need to be conscious of security concerns. Ovid's Online CGI Course (free) does a pretty good job of getting your feet wet in the area of starting to understand security issues.

    I personally like the Mouse Book (CGI Programming with Perl, from O'Reilly & Associates). It has a great description of how to handle file uploads, and goes to the trouble of explaining how to deal with keeping the process relatively secure. You may find a copy in the library, but if you do much with CGI, it's a good resource to have on your own bookshelf.

    I hope this helps...


    Dave