Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: mod_perl upload woes

by edoc (Chaplain)
on Jan 12, 2004 at 23:21 UTC ( #320809=note: print w/replies, xml ) Need Help??


in reply to mod_perl upload woes

I've implemented uploads in mod_perl with no apparent dramas.. The first time (a couple years back) it took me a while to get my head around it, but I tackled it the other day again and was chuffed at how easy it was.

What errors/symptoms are you guys seeing?

when i add into the second links code something like
%args=$r->args;
my $saveto=$args{saveto};

Have you tried:

my $saveto = $r->param('saveto');

cheers,

J

Replies are listed 'Best First'.
Re: Re: mod_perl upload woes
by drfrog (Deacon) on Jan 13, 2004 at 00:56 UTC
    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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://320809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2022-01-28 13:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (73 votes). Check out past polls.

    Notices?