CGI.pm upload()

D

D Borland

Hi Folks,

Can anyone here tell me if there is a safe alternative to CGI.pm's upload
function?

There main reason for needing this is that i am needing to upload multiple
files, (eg. image1, image2, image3, image4), but you can only pass the
upload function an actual param not a $scalar value, so this means i have to
specify each upload i will need and that means 4 times as much code, but
most of all is that when it fails to upload the files, it's impossible to
see what it failed on and why.

Hope i explained that OK :)

Thanks
 
A

Alan J. Flavell

Can anyone here tell me if there is a safe alternative to CGI.pm's upload
function?

In what sense do you consider CGI.pm unsafe?
There main reason for needing this is that i am needing to upload multiple
files, (eg. image1, image2, image3, image4), but you can only pass the
upload function an actual param not a $scalar value, so this means i have to
specify each upload i will need and that means 4 times as much code,

I don't quite understand your point. The current documentation says:

| You can have several file upload fields in the same form, and even
| give them the same name if you like (in the latter case param() will
| return a list of file names).
but most of all is that when it fails to upload the files, it's
impossible to see what it failed on and why.

That's awfully vague. If you have a Perl problem, let's see some
snippets of Perl here.

If your problem is more about how to organise your CGI script to do
what you want, rather than anything Perl-specific, you might be better
placed on comp.infosystems.www.authoring.cgi (check its automoderation
FAQ before posting).

good luck.
 
D

David Efflandt

Can anyone here tell me if there is a safe alternative to CGI.pm's upload
function?

There main reason for needing this is that i am needing to upload multiple
files, (eg. image1, image2, image3, image4), but you can only pass the
upload function an actual param not a $scalar value, so this means i have to
specify each upload i will need and that means 4 times as much code, but
most of all is that when it fails to upload the files, it's impossible to
see what it failed on and why.

The first thing a newbie needs to learn is how to include error checking
in your code, so your script will be nice enough to tell you what is
wrong. But that assumes that you tested it in a shell first to eliminate
precompile errors (like missing ';' or mismatched quotes or brackets).

You could download multiple files (like consecutively numbered names) with
a loop (function method example).

# assuming any 1 to 5 files w/field names image1..image5
for $i (1..5) {
my $upload;
if ($upload = param('image'.$i)) {
# Pull filename from end of any browser supplied path
if ($upload =~ m|[/\\:]|) {
$upload =~ m|[/\\:]+([^/\\:]+)$|;
$upload = $1;
}
# add filename tests to assure compatible/non-conflicting name
# like substitute underlines for spaces, etc.
# do something useful with $upload
}
}
 
A

Anno Siegel

D Borland said:
Hi Folks,

Can anyone here tell me if there is a safe alternative to CGI.pm's upload
function?

There main reason for needing this is that i am needing to upload multiple
files, (eg. image1, image2, image3, image4), but you can only pass the
upload function an actual param not a $scalar value, so this means i have to
specify each upload i will need and that means 4 times as much code, but
most of all is that when it fails to upload the files, it's impossible to
see what it failed on and why.

Hope i explained that OK :)

It comes across a little breathless. A period or two would have helped.

Anno
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top