You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Sam Carleton <sc...@activex-dev.com> on 2000/04/30 03:44:33 UTC
perl code to handle a multipart/form-data POST
I am in a very tight spot right now. I need to have some C++ code
posting data to a web browser vi 'multipart/form-data' by Monday. I
would REALLY like to have either a normal perl CGI script or mod_perl
script that will simply display all the information POSTed to it from my
code. Is anyone up to the task, or able to give me some pointers on how
I can do this myself?
Sam Carleton
Re: perl code to handle a multipart/form-data POST
Posted by Ron Pero <rp...@boone.net>.
Dear Sam
CGI.pm is the module of choice on this. It comes with the standard
distribution, so you already have it (probably). In the documentation, go
to the section titled, CREATING A FILE UPLOAD FIELD. It is easy.
Ron
At 10:33 PM 04/29/00 -0400, Sam Carleton wrote:
>Sam Carleton wrote:
>>
>> I am in a very tight spot right now. I need to have some C++ code
>> posting data to a web browser vi 'multipart/form-data' by Monday. I
>> would REALLY like to have either a normal perl CGI script or mod_perl
>> script that will simply display all the information POSTed to it from my
>> code. Is anyone up to the task, or able to give me some pointers on how
>> I can do this myself?
>
>I LOVE answering my own questions:
>
>#! /usr/bin/perl
>
>#cgi-lib.pl was optained from http://cgi-lib.berkeley.edu/
>require "cgi-lib.pl";
>
>ReadParse();
>
>print PrintHeader();
>print HtmlTop("POST/GET Display");
>print PrintVariables();
>print HtmlBot();
>
>exit 0;
>
>
Re: Apache::Request->new($r) does NOT work, why?
Posted by Tobias Hoellrich <th...@Adobe.COM>.
At 02:04 PM 4/30/00 -0400, Sam Carleton wrote:
>Tobias,
>
>The new is blowing up on me. This is the error message:
>
>null: Can't locate object method "new" via package "Apache::Request"
Try installing it :-)
$ perl -MCPAN -e shell
cpan> install Apache::Request
Tobias
PS: Please, please read the guide at http://perl.apache.org/- everything is
in there. If you schedule is too tight to read the guide, rethink your
schedule.
Apache::Request->new($r) does NOT work, why?
Posted by Sam Carleton <sc...@activex-dev.com>.
Tobias Hoellrich wrote:
> Almost :-) Apache cannot be used for multipart/form-data, gotta use
> Apache::Request instead. Change the start of the handler to :
>
> sub handler {
> my $r = shift;
> my $apr = Apache::Request->new($r)
Tobias,
The new is blowing up on me. This is the error message:
null: Can't locate object method "new" via package "Apache::Request"
Re: perl code to handle a multipart/form-data POST
Posted by Tobias Hoellrich <th...@Adobe.COM>.
At 01:49 PM 4/30/00 -0400, Sam Carleton wrote:
>
>Tobias,
>
>I am looking into it right now, but you might be able to save me a lot
>of time. I want to display the name/values from the HTML form. How
>would I go about enumerating through the @params to do this?
>
>Sam
How bout this:
package Apache::POSTDisplay;
use strict;
use Apache::Constants qw(:common);
use Apache::Request ();
use Apache::Util ();
sub handler {
my $r = shift;
my $apr=Apache::Request->new($r);
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
my
$html=qq{<html><body><title>POSTDisplay</title><body><h1>POSTDisplay</h1><ul>};
foreach my $key ($apr->param) {
my $val=Apache::Util::escape_html($apr->param($key));
$html.=qq{<li>[$key] = [$val]\n};
}
$html.=qq{</ul>\n</body>\n};
$r->print($html);
return OK;
}
1;
Tobias
Re: perl code to handle a multipart/form-data POST
Posted by Sam Carleton <sc...@activex-dev.com>.
Tobias Hoellrich wrote:
>
> Almost :-) Apache cannot be used for multipart/form-data, gotta use
> Apache::Request instead. Change the start of the handler to :
>
> sub handler {
> my $r = shift;
> my $apr = Apache::Request->new($r)
>
> and then get the params with @params=$apr->param;
Tobias,
I am looking into it right now, but you might be able to save me a lot
of time. I want to display the name/values from the HTML form. How
would I go about enumerating through the @params to do this?
Sam
Re: perl code to handle a multipart/form-data POST
Posted by Tobias Hoellrich <th...@Adobe.COM>.
At 01:29 PM 4/30/00 -0400, Sam Carleton wrote:
>
> Ok, So cgi-lib.pl isn't the greatest in the world, but it did help me
> get a big farther in my project:) Now I need something that works. I
> have "Writing Apache Modules with Perl and C", but have not read too
> deep into it and time is very short. Again, all I am trying to do is
> print out ALL the name/values that was on the form. The code I have so
> far does not display any of the name/values, Below is my code, could
> someone please show me what I am doing wrong and how do I fix it?
>
> package Apache::POSTDisplay;
>
> use strict;
> use Apache::Constants qw(:common);
>
> sub handler {
> my $r = shift;
>
> $r->content_type('text/html');
> $r->send_http_header;
> $r->print(<<HTTP_HEADER);
>
>
> POSTDisplay
>
>
> HTTP_HEADER my @args = ($r->args, $r->content); while(my($name,$value) =
> splice @args,0,2) { $r->print("
> * [$name]=[$value]\n"); } $r->print(<
> * </HTML> HTTP_FOOTER
>
> return OK; }
>
> 1; __END__
Almost :-) Apache cannot be used for multipart/form-data, gotta use
Apache::Request instead. Change the start of the handler to :
sub handler {
my $r = shift;
my $apr = Apache::Request->new($r)
and then get the params with @params=$apr->param;
Hope this helps
Tobias
Re: perl code to handle a multipart/form-data POST
Posted by Sam Carleton <sc...@activex-dev.com>.
"Jeffrey W. Baker" wrote:
>
> On Sat, 29 Apr 2000, Sam Carleton wrote:
>
> > #! /usr/bin/perl
> >
> > #cgi-lib.pl was optained from http://cgi-lib.berkeley.edu/
> > require "cgi-lib.pl";
>
> If we can erradicate polio and small pox, surely there must be a way to
> rid the world of cgi-lib.pl. Apparently it can still strike the young,
> elderly, and infirm. What a senseless waste.
>
> -jwb
>
> PS. If Mr. Carleton is not in too much of a hurry, I would advise him to
> look into the modern software available on CPAN, such as Apache.pm, which
> comes with mod_perl, and Apache::Request, which is available at
> http://www.perl.com/CPAN/modules/by-module/Apache/.
Ok, So cgi-lib.pl isn't the greatest in the world, but it did help me
get a big farther in my project:) Now I need something that works. I
have "Writing Apache Modules with Perl and C", but have not read too
deep into it and time is very short. Again, all I am trying to do is
print out ALL the name/values that was on the form. The code I have so
far does not display any of the name/values, Below is my code, could
someone please show me what I am doing wrong and how do I fix it?
package Apache::POSTDisplay;
use strict;
use Apache::Constants qw(:common);
sub handler {
my $r = shift;
$r->content_type('text/html');
$r->send_http_header;
$r->print(<<HTTP_HEADER);
<HTML>
<TITLE>POSTDisplay</TITLE>
<BODY>
<H1>POSTDisplay</H1>
<UL>
HTTP_HEADER
my @args = ($r->args, $r->content);
while(my($name,$value) = splice @args,0,2) {
$r->print("<li>[$name]=[$value]</li>\n");
}
$r->print(<<HTTP_FOOTER);
</UL>
</BODY></HTML>
HTTP_FOOTER
return OK;
}
1;
__END__
Re: perl code to handle a multipart/form-data POST
Posted by "Jeffrey W. Baker" <jw...@acm.org>.
On Sat, 29 Apr 2000, Sam Carleton wrote:
> #! /usr/bin/perl
>
> #cgi-lib.pl was optained from http://cgi-lib.berkeley.edu/
> require "cgi-lib.pl";
If we can erradicate polio and small pox, surely there must be a way to
rid the world of cgi-lib.pl. Apparently it can still strike the young,
elderly, and infirm. What a senseless waste.
-jwb
PS. If Mr. Carleton is not in too much of a hurry, I would advise him to
look into the modern software available on CPAN, such as Apache.pm, which
comes with mod_perl, and Apache::Request, which is available at
http://www.perl.com/CPAN/modules/by-module/Apache/.
Re: perl code to handle a multipart/form-data POST
Posted by Sam Carleton <sc...@activex-dev.com>.
Sam Carleton wrote:
>
> I am in a very tight spot right now. I need to have some C++ code
> posting data to a web browser vi 'multipart/form-data' by Monday. I
> would REALLY like to have either a normal perl CGI script or mod_perl
> script that will simply display all the information POSTed to it from my
> code. Is anyone up to the task, or able to give me some pointers on how
> I can do this myself?
I LOVE answering my own questions:
#! /usr/bin/perl
#cgi-lib.pl was optained from http://cgi-lib.berkeley.edu/
require "cgi-lib.pl";
ReadParse();
print PrintHeader();
print HtmlTop("POST/GET Display");
print PrintVariables();
print HtmlBot();
exit 0;