Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

mod_perl file upload "end of file found" Or undefined filehandle

by Jerzy2012 (Initiate)
on Nov 28, 2012 at 00:29 UTC ( #1005944=perlquestion: print w/replies, xml ) Need Help??
Jerzy2012 has asked for the wisdom of the Perl Monks concerning the following question:

Hello fellow Perl coders.

I spent half a day looking for a solution and didn't find a working one. I would appreciate any help.

I am trying to do a simple web based file upload script. It's a part of bigger project so I am using mod_perl (ModPerl::Registry)

In my main class named I have following code:
my $cgi = CGI->new; my $self = { OBJ_cgi => $cgi };

In my module I have:

my $r = Apache2::RequestUtil->request; my $req = Apache2::Request->new($r); my @upload = eval { $req->upload() }; print STDERR Dumper($@);
This gives me:
NAMES: $VAR1 = bless( { 'rc' => 70014, '_r' => bless( do{\(my $o = '140573114765624')}, 'Apa +che2::Request' ), 'file' => '/usr/lib/perl5/APR/', 'func' => 'APR::Request::body', 'line' => 50 }, 'APR::Request::Error' );
If I execute it without eval, it throws following code in apache error log file:
[error] End of file found

My HTML form:

<form action="uploaddocument.cgi" method="POST" enctype="multi +part/form-data"> <input type="file" name="file_content"> <input type="hidden" name="id" value="2"> <input type="hidden" name="save" value="1"> <input type="submit" value="Upload file"> </form>

I checked it on two browsers(chrome, firefox). I checked this code on two different servers(Debian and CentOS). It doesn't work anywhere.

I tried to use a way of handling files:

my $fh = $self->{OBJ_cgi}->upload('file_content'); print STDERR Dumper($fh);

And this prints undef to STDERR

The interesting part is that it correctly reads the name of file if I use param method instead of upload. Also during the script execution the file is correctly saved in /var/tmp/CGItemp...

I would be extremely grateful for any help.
Best regards,


I managed to get this thing working. In in method new - first method that is executed at all - I added:
my $r = Apache2::RequestUtil->request; my $req = Apache2::Request->new($r);

I don't do anything with these objects. I don't pass those anywhere. I can even undef both of those right after declaring it. So my question changes to: Why this works after adding those 2 lines?

Replies are listed 'Best First'.
Re: mod_perl file upload "end of file found" Or undefined filehandle
by Anonymous Monk on Nov 28, 2012 at 01:49 UTC
Re: mod_perl file upload "end of file found" Or undefined filehandle
by Anonymous Monk on Nov 28, 2012 at 01:44 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1005944]
Approved by frozenwithjoy
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2018-03-23 17:17 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (295 votes). Check out past polls.