Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

mod_perl file upload "end of file found" Or CGI.pm 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 Main.pm I have following code:
my $cgi = CGI->new; my $self = { OBJ_cgi => $cgi };

In my module File.pm 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/Request.pm', '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 CGI.pm 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,
Jerzy

UPDATE

I managed to get this thing working. In Main.pm 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?

Comment on mod_perl file upload "end of file found" Or CGI.pm undefined filehandle
Select or Download Code
Re: mod_perl file upload "end of file found" Or CGI.pm undefined filehandle
by Anonymous Monk on Nov 28, 2012 at 01:44 UTC
Re: mod_perl file upload "end of file found" Or CGI.pm undefined filehandle
by Anonymous Monk on Nov 28, 2012 at 01:49 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1005944]
Approved by frozenwithjoy
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (8)
As of 2014-11-27 07:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (180 votes), past polls