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

Discussion in 'Perl Misc' started by roadrunner, Feb 7, 2006.

  1. roadrunner

    roadrunner Guest

    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.
    roadrunner, Feb 7, 2006
    #1
    1. Advertising

  2. roadrunner wrote:
    > 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__

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
    Gunnar Hjalmarsson, Feb 8, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jürgen Exner

    Re: CGI Perl "use CGI" statement fail

    Jürgen Exner, Jul 31, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,254
    Jürgen Exner
    Jul 31, 2003
  2. Alfred Z. Newmane

    Re: [OT] Re: "use CGI " hangs "CGI time out "

    Alfred Z. Newmane, Jun 23, 2005, in forum: C Programming
    Replies:
    13
    Views:
    622
    Stan R.
    Jun 24, 2005
  3. Guy
    Replies:
    4
    Views:
    786
    Malcolm Dew-Jones
    Dec 11, 2003
  4. GMI
    Replies:
    25
    Views:
    442
    Tad McClellan
    Jun 24, 2005
  5. nick
    Replies:
    1
    Views:
    450
    David Mark
    Feb 13, 2011
Loading...

Share This Page