You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Stephan Jennewein <xt...@cccmz.de> on 2007/02/08 00:49:23 UTC

Unaltered cgi upload

Hi,

I want to change a cgi script to run with mod_perl, but I have a problem
with the DIE signal I used in an earlier version to clean the directory
if the user presses the stop button during the upload.

local $SIG{__DIE__} = \&cleanup;

But this doesn't work with mod_perl2 and apache2. How can I handle this
now?

And if something goes wrong with the upload a $cgi->redirect should send
the user to another page can I use this with mod_perl and the exit()
after the redirect doesn't work. The website told me that
ModPerl::Registry will overwrite the native exit() function but it
doesn't seems so. How can I fix this?

I'm using mod_perl 2.0.2 and apache 2.2.3 .

Thanks in advance 

Stephan

Re: Unaltered cgi upload

Posted by "Dondi M. Stroma" <ds...@verizon.net>.
Hi,

I don't think you have to worry about using die or exit it all. The CGI.pm 
documentation says the following:

"There are occasionally problems involving parsing the uploaded file. This 
usually happens when the user presses "Stop" before the upload is finished. 
In this case, CGI.pm will return undef for the name of the uploaded file and 
set cgi_error() to the string "400 Bad request (malformed multipart POST)". 
This error message is designed so that you can incorporate it into a status 
code to be sent to the browser."

Hope this helps. 


Re: Unaltered cgi upload

Posted by Stephan Jennewein <xt...@cccmz.de>.
I changed the cleanup stuff to a perlcleanup handler, but I want to
check if the temp directory, where the upload should store stuff, does
already exist. and if it's exist quit immediately but since I switched
to modperl it waits until the whole upload has finished before it quit.

Changeing exit() to Apache2::Const::OK didn't help.
$r->discard_request_body(); <-- doesn't help at all 

if(-d $sid)
{
  $r->set_handlers(PerlCleanupHandler => undef);
  $r->discard_request_body(); 
  my $cgi = new CGI;
  print $cgi->redirect('/upload/?error=1&sid=duplicated');
  exit;
}


This peace of codes is in front of the cgi upload, but it doesn't seem
to be handled before the upload is finished. Why ?

Re: Unaltered cgi upload

Posted by Perrin Harkins <ph...@gmail.com>.
On 2/7/07, Stephan Jennewein <xt...@cccmz.de> wrote:
> local $SIG{__DIE__} = \&cleanup;

Make that a PerlCleanupHandler.

> And if something goes wrong with the upload a $cgi->redirect should send
> the user to another page can I use this with mod_perl and the exit()
> after the redirect doesn't work.

You were using exit like a return, to avoid running the rest of the
script?  You can use ModPerl::Util::exit (which will log an error), or
return Apache2::Const::OK, or just stop printing.

- Perrin