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

Hi Fellow Monks, I'm a bare novice, so please bear with me. I need a subroutine that would allow me to upload several images and write some input to a text file all at once. Does anyone know how to do this? Please let me know. Thanks! Tim

Replies are listed 'Best First'.
Re: Uploading and writing to a text file
by Jouke (Curate) on Oct 05, 2000 at 09:44 UTC
    You might take a look at the documentation provided with the CGI.pm module. Look for the upload() method, and play around with example code. Learning by playing around helps more than getting a full-featured script from anyone here (IMHO)

    Jouke Visser, Perl 'Adept'
Re: Uploading and writing to a text file
by swiftone (Curate) on Oct 05, 2000 at 18:10 UTC
    Hi Fellow Monks,

    Hi!

    I'm a bare novice, so please bear with me.

    Okay, turning off flamethrower. As a tip, when asking for help, you should try to:

    1. Be very specific about what you are trying to do
    2. Either post the code you attempted to use, or explain why you have no code.
    3. Be very specific about what happens when something "doesn't work".
    4. Always have use strict; in your program, and have a -w as a command line option, such as #!/usr/bin/perl -w. If you're writing a web script, have #!/usr/bin/perl -wT
    In some areas, notable some Perl Usenet newgroups, you can get some very vicious comments if you don't.

    I need a subroutine that would allow me to upload several images and write some input to a text file all at once.

    Okay. There are multiple issues here.

    1. Writing to a text file

      This is easily done in perl. Check out the documentation for open, close, and print.

    2. Uploading files

      Here is an instance of not being specific about the problem. "Uploading" can happen various ways. I'll assume you mean via a Web page, but if you don't, please clarify.

      As mentioned, you should use the CGI.pm module. If you aren't familiar with using modules, you should learn, as it is the single best time saver in perl (and there are a lot). A good place to start is perlmodlib.

      The documentation for CGI.pm is a bit...rambling. If you're familiar with HTML, I'd recommend you skip the sections describing HTML-generating functions for now. You'll want to look at the param(), header(), and upload() functions. Also notice that you need to properly set the enctype field for your form (details in the CGI documentation).

    You may want to look at the thread File Upload to Selected Directory. Be sure to read the responses, they contain good security information.