--- Teresa Raymond <[EMAIL PROTECTED]> wrote:
> I would like to write a script that allows advertisers to send their 
> ads via their browser.  I don't even know where to begin on this one. 
> My preliminary questions are:
> 
> 1.  Do I need to set parameters regarding what file types they are 
> sending?  What sort of parameters?
> 2.  Do I need to set parameters regarding their file size?
> 3.  What are the perl commands to open their file search to select a 
> file from their hard disk?
> 4.  How do I attach that file to my cgi prog?
> 5.  My assumptions are that I'll have to create a tempfile of their 
> uploaded file, after sending the file, delete the tempfile.
> 
> Any and all advice is welcome, including what book, where in perldoc, etc...
> 
> *** Teresa Raymond
> *** http://www.mariposanet.com
> *** [EMAIL PROTECTED]

Hoo boy.  That's a doozy of a question in large part due to the way that CGI.pm 
handles uploads. 
CGI.pm has changed the interface a few times (regarding uploads) and you'll want to 
make sure that
you have the latest version possible, as earlier versions tended to be buggy.

Before I answer your questions, I have to say that you'll need to understand how file 
uploads work
with the CGI.pm module.  Here's a post I made when I had a complete braincramp and 
missed a
'binmode' on a filehandle:  http://www.perlmonks.org/index.pl?node_id=73962

I offer that post as an example of how to handle file uploads.  The code requires 
5.6.0 or above.

1.  Do I need to set parameters regarding what file types they are sending?  What sort 
of
parameters?

That's up to you.  Tell the advertisers you'll only accept .gif or .jpg images (or 
whatever you're
accepting) and then validate the image type in the code.

After getting a file handle (we'll assume the handle is called $file), you can check 
the
content-type with the following:

#!/usr/bin/perl -wT
use strict;
use CGI;

my $cgi    = CGI->new;
my $file   = $cgi->upload( "advert" ) or error( $cgi->p( "No file uploaded." ) );
my $format = $cgi->uploadInfo( $file )->{ 'Content-Type' };

See above link for more info.

2.  Do I need to set parameters regarding their file size?

Yes.  Otherwise, someone could send huge files and fill up your disk space.  Also, be 
sure to
check if the aggregate uploads are excessive, even if a particular upload is okay.

To limit the size of uploads, set $CGI::POST_MAX to the number of bytes per upload.

3.  What are the perl commands to open their file search to select a file from their 
hard disk?

You cannot do that from a Web-based app.  Present the user with a Web form and have 
one of the
inputs something like:

<input type="file" name="advert">

>From the Perl script, you can get a filehandle for this with:

my $file = $cgi->upload( "advert" ) or some_error_routine( "No file uploaded." );

4.  How do I attach that file to my cgi prog?

See 3. above.

5.  My assumptions are that I'll have to create a tempfile of their uploaded file, 
after sending
the file, delete the tempfile.

CGI.pm handles this for you.  Again, see the link I provided.  You have asked a lot of 
questions
and they are very difficult ones to succintly answer.

Hope this helps.

Cheers,
Curtis Poe

=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__________________________________________________
Do You Yahoo!?
Get personalized email addresses from Yahoo! Mail - only $35 
a year!  http://personal.mail.yahoo.com/

Reply via email to