Hi folks.  I'm new to the list, and relatively new to mod_perl, but a
big project thrown my way put me right in the middle, and I think I've
fared well so far, with one exception... file uploads.  I've based my
code off the apache::request documentation and the file upload code
snippet posted here and on the perl.apache.org site.

I have the following configured:


<Location /upload>
        SetHandler perl-script
        PerlHandler Test::Upload
        PerlInitHandler Apache::StatINC
</Location>

My Test/Upload.pm looks something like this:

---------------------------------
package Test::Upload;
use strict;
use Apache::Constants qw(:common);
use Apache::Log;
use Apache::File();
use Apache::Request;

sub handler {
   my $r = shift;

   my $form = form();

   if (my $file = $form->{UPLOAD})
   {
      my $filelocation="/home/alan/code/test/htdocs/files";
      my $filename = $file->filename; # If you need the name
      open F, ">$filelocation";
      my $filehandle = $file->fh;
      while (my $d = <$filehandle>) 
      {
         print F $d;
      }
      close F;
   }

   $r->content_type('text/html');
   $r->send_http_header;
   print <<END;
<form enctype="multipart/form-data" method=post action=/upload>
<input type=hidden name=form value=content>
Upload a file: <input type=file> <input type=submit name=upload value=upload>
</form>
END

   return OK;
}

1;

# This is a copy of the form code from the snippets page
sub form {
   use Apache::Request;
   my $r = Apache->request();
   my $apr = Apache::Request->new($r, DISABLE_UPLOADS => 1);
   my @keys = $apr->param;

   my %form;
   foreach my $key(@keys) {

      my @value = $apr->param($key);
      next unless scalar @value;

      if ( @value > 1 ) {
         $form{$key} = \@value;
      } else {
         $form{$key} = $value[0];
      }
   }

   my $upload = $apr->upload;
   if ($upload) {
      $form{UPLOAD} = $upload;
   }

   return \%form;
}

---------------------------------

As far as I can tell, the code should see the upload, grab the upload
via $apr->upload, and use it.  However, nothing happens. 

Even if I put in copious debug (for example, code that prints out when
if($upload){ } is hit), nothing.  It's as if the upload is not taking
place at all.

Can anyone give me a hand with this, I'm literally beating my head
against the table!

TIA

Alan

-- 
Alan "Arcterex" <[EMAIL PROTECTED]>   -=][=-   http://arcterex.net
"I used to herd dairy cows. Now I herd lusers. Apart from the isolation, I
think I preferred the cows. They were better conversation, easier to milk, and
if they annoyed me enough, I could shoot them and eat them." -Rodger Donaldson

Reply via email to