CGI - How to use upload_hook and query the query string ?

R

roadrunner

Hi,

I'm using the CGI::upload_hook functionality and would like to get a
parameter value passed in via POST *before* calling the upload hook to
process files. i.e. Something like this:

my $query = new CGI();<br/>
$query->param("myParam");<br/>
$query->new(\&hook);

Now according to the CGI docs this doesn't look possible:

"If using the function-oriented interface, call the CGI::upload_hook()
method before calling param() or any other CGI functions:
CGI::upload_hook(\&hook,$data);"

....and indeed my exprience bears this out - If I try and query any
params before calling the upload hook I get missing data in the hook.
Does anyone know of a way round this - i.e. querying parameter values
before calling an upload hook ?

Thanks,
roadrunner.
 
G

Gunnar Hjalmarsson

roadrunner said:
I'm using the CGI::upload_hook functionality and would like to get a
parameter value passed in via POST *before* calling the upload hook to
process files. i.e. Something like this:

my $query = new CGI();<br/>
$query->param("myParam");<br/>
$query->new(\&hook);

Now according to the CGI docs this doesn't look possible:

"If using the function-oriented interface, call the CGI::upload_hook()
method before calling param() or any other CGI functions:
CGI::upload_hook(\&hook,$data);"

...and indeed my exprience bears this out - If I try and query any
params before calling the upload hook I get missing data in the hook.
Does anyone know of a way round this - i.e. querying parameter values
before calling an upload hook ?

I don't have a direct answer to your question, but you may be able to
achieve the same thing by using CGI::UploadEasy:

use CGI::UploadEasy;
my $uploaddir = '/path/to/upload/directory';
my $ue = CGI::UploadEasy->new(-uploaddir => $uploaddir);
my $info = $ue->fileinfo;
my $cgi = $ue->cgiobject;
print $cgi->header;
print $cgi->param('myParam'), "<br />\n";
for my $file ( keys %$info ) {
print "Read $info->{$file}{bytes} bytes of $file<br />\n";
}
__END__
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top