NAME
Apache::ParseFormData - Perl extension for dealing with client request data
SYNOPSIS
use Apache::RequestRec ();
use Apache::RequestUtil ();
use Apache::RequestIO ();
use Apache::Log;
use Apache::Const -compile => qw(DECLINED OK);
use Apache::ParseFormData;
sub handler {
my $r = shift;
my $apr = Apache::ParseFormData->new($r);
my $scalar = 'abc';
$apr->param('scalar_test' => $scalar);
my $s_test = $apr->param('scalar_test');
print $s_test;
my @array = ('a', 'b', 'c');
$apr->param('array_test' => \@array);
my @a_test = $apr->param('array_test');
print $a_test[0];
my %hash = {
a => 1,
b => 2,
c => 3,
};
$apr->param('hash_test' => \%hash);
my %h_test = $apr->param('hash_test');
print $h_test{'a'};
$apr->notes->clear();
return Apache::OK;
}
ABSTRACT
The Apache::ParseFormData module allows you to easily decode and parse form and query data, even multipart forms generated by "file upload". This module only work with mod_perl 2.
DESCRIPTION
Apache::ParseFormData
extension parses a GET and POST requests, with multipart form data input stream, and saves any files/parameters encountered for subsequent use.
Apache::ParseFormData METHODS
new
Create a new Apache::ParseFormData object. The methods from Apache class are inherited. The optional arguments which can be passed to the method are the following:
- temp_dir
-
Directory where the upload files are stored.
param
Like CGI.pm you can add or modify the value of parameters within your script.
my $scalar = 'abc';
$apr->param('scalar_test' => $scalar);
my $s_test = $apr->param('scalar_test');
print $s_test;
my @array = ('a', 'b', 'c');
$apr->param('array_test' => \@array);
my @a_test = $apr->param('array_test');
print $a_test[0];
my %hash = {
a => 1,
b => 2,
c => 3,
};
$apr->param('hash_test' => \%hash);
my %h_test = $apr->param('hash_test');
print $h_test{'a'};
upload
You can access the name of an uploaded file with the param method, just like the value of any other form element.
my %file_hash = $apr->param('file');
my $filename = $file_hash{'filename'};
my $content_type = $file_hash{'type'};
my $size = $file_hash{'size'};
for my $upload ($apr->upload()) {
my $form_name = $upload->[0];
my $fh = $upload->[1];
my $path = $upload->[2];
while(<$fh>) {
print $_;
}
my %file_hash = $apr->param($form_name);
my $filename = $file_hash{'filename'};
my $content_type = $file_hash{'type'};
my $size = $file_hash{'size'};
unlink($path);
}
SEE ALSO
libapreq, Apache::Request
CREDITS
This interface is based on the libapreq by Doug MacEachern.
AUTHOR
Henrique Dias, <hdias@aesbuc.pt>
COPYRIGHT AND LICENSE
Copyright 2003 by Henrique Dias
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.