in reply to Re: mod_perl upload woes
in thread mod_perl upload woes

hmm i dont know what kind of problems i was having earlier, but now coffee seems to have helped!!

i think part of this might have to do with getting parameter in these two ways, which just made sense when edoc showed me the line:
#normal $r from my POV sub handler { my $r=Apache::request(); %args=$r->args; my $sitename=$args{sitename}; }
or
#$apr sub handler { my $r=Apache::request(); my $apr = Apache::Request->new( $r , POST_MAX => 10 * 1024 * 1024, # in byte +s, so 10M DISABLE_UPLOADS => 0); my $sitename = $apr->param('sitename'); }
it seems obvious that $apr loads parameters in differently ? or am i mistaken/used to Apache::request as opposed to Apache::Request? here is the working code

package PP::Uploads; use Apache::Constants qw(OK); use Apache::Request; use Apache::Util qw(escape_html); use strict; sub handler { # Standard stuff, with added options... my $r = Apache::Request->new(shift, POST_MAX => 10 * 1024 * 1024, # in byte +s, so 10M DISABLE_UPLOADS => 0); my $status = $r->parse(); my $sitename = $r->param('sitename'); # Return an error if we have problems. return $status unless $status == OK; $r->send_http_header('text/html'); $r->print("<html><body>\n"); $r->print("<h1>Upload files</h1>"); # Iterate through each uploaded file. foreach my $upload ($r->upload) { my $filename = $upload->filename; my $filehandle = $upload->fh; my $size = $upload->size; $r->print("You sent me a file named $filename, $size bytes<br>"); $r->print("The first line of the file is: <br>"); my $dir="/tmp/$sitename/"; my $line; while ( <$filehandle>) { $line.=$_; } mkdir $dir; my $image=$dir.$filename; open FH ,">$image" or die $!; print FH $line; close FH; # $r->print(escape_html($line), "<br>"); } $r->print("Done......<br>"); # Output a simple form. $r->print(<<EOF); <form enctype="multipart/form-data" name="files" action="/PP/upload" + method="POST"> <input type=hidden name=sitename value=$sitename> File 1 <input type="file" name="file1"><br> File 2 <input type="file" name="file2"><br> File 3 <input type="file" name="file3"><br><br> <input type="submit" name="submit" value="Upload these files"> </form> </body></html> EOF return OK; }; 1;