--- Lynn Glessner <[EMAIL PROTECTED]> wrote:
> I have copied a script out of "CGI programming with perl", to see if I
> understand how uploading a file would work. So far it doesn't - the code
> checks correctly with perl -c but then I get an internal server error 500. I
> think I found a minor error in the book example already :( Can anyone help?
> I have apache and perl 5.6.0.
Lynn,
I have a couple of thoughts on this.
1. For some reason, many, many people (including myself) seem to have problems when
using the
CGI::upload method. I don't know why this is, but I tend to avoid it as a result.
2. You may want to consider ugrading to 5.6.1. 5.6.0 is considered to be a
development release
and has some significant memory leaks that 5.6.1 fixes.
To solve your problem, you may want to consider the CGI::Safe module that I've
written. You can
obtain it at http://www.perlmonks.org/index.pl?node_id=104626. There is a 'd/l code'
link at the
bottom. Save the file in your /perl/lib/CGI directory as Safe.pm. Full POD is
included. If
you're not familiar with POD, after installing the module, you can type 'perldoc
CGI::Safe' for
complete instructions how to use it. Also note that this module is a subclass of
CGI.pm and does
not change anything at all, so none of your other programs will be affected.
CGI::Safe makes CGI scripting a bit safer by tweaking some of the defaults in CGI.pm
and deleting
some dangerous %ENV variables. For the vast majority of CGI scripts, the only change
necessary is
to drop the 'use CGI' lines and object instantiation and use the following:
use CGI::Safe;
my $q = CGI::Safe->new();
If you prefer the function oriented method, this is also supported:
use CGI::Safe qw/:standard/;
print header,
start_html,
# etc.
In your case, since file uploads are disabled by default, you will need to re-enable
them. Here
is a minimal test case:
use strict;
use CGI::Safe;
use constant MAX_FILE_SIZE => 1_048_576; # Limit each upload to 1 MB
my $q = CGI::Safe->new( DISABLE_UPLOADS => 0,
POST_MAX => MAX_FILE_SIZE );
my $file = $q->get_upload( file_name => 'somefilename' );
if ( $file->{ error } ) {
print $q->header,
$q->start_html,
$q->p( $file->{ error } ),
$q->end_html;
} else {
print $q->header( -type => $file->{ format } ),
$file->{ file };
}
As you can see, this makes uploading much simpler. I'm still looking for feedback on
this module,
so if you use it (it's beta), please let me know how it works if you decide to use it.
As a side note, you can also specify the file types that you allow, thereby
restricting filetypes
that you don't want, or even pass the routine a separate CGI object that contains the
upload, if
you ever had cause to do that.
Cheers,
Curtis Poe
=====
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/
__________________________________________________
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]