in reply to cgi and upload_hook

This assumes you have no need to associate the file upload with the field name (ie single file upload in the whole form). You could arrange your script to be a 404 handler and pass the information needed in url instead (http://example.com/myFile_sessionID). In other words put the "field name" (myFile) as part of the action url instead of the real field name.

# example only, need proper sanitization here in real life my ($name)=$ENV{REQUEST_URI}=~/(\w+)$/; my @param=split /_/,$name;

You also need to change REQUEST_METHOD in your script to REDIRECT_REQUEST_METHOD.

Replies are listed 'Best First'.
Re^2: cgi and upload_hook
by qbxk (Friar) on May 26, 2006 at 10:28 UTC
    I'm won't do this as a redirect, but your idea is good - to just add the crucial info to the action string. it's not great, as it's not ok to do it this way in some cases (multiple file upload forms), but for my needs right now it will ensure that i get that field name from the form every time, so i won't be at the mercy of the browser deciding in which order to put my post variables.

    your issue of redirection though, that's an odd solution. i think the problem you're trying to solve is that CGI won't expose variables on the url (GET vars) during a POST. my solution to that is as follows:
    my $get_cgi = new CGI( $ENV{REDIRECT_QUERY_STRING} || $ENV{QUERY_STRIN +G}); my $cgi = new CGI; #will read ALL of STDIN (file uploads will take tim +e..) my $all_vars = \%{ $cgi->Vars, $get_cgi->Vars }; #GET vars will take p +recedence.
    the problem with this code is that if you have multiple fields with the same name you lose some values, but if you have that situation you need to build your own hash more explicitly, by calling $cgi->param on each variable until there's nothing left. but this does illustrate my concept: use 2 cgi instances, one for GET and one for POST and merge them

    thanks for your insight [id://daitau]

    It's not what you look like, when you're doin' what you’re doin'.
    It's what you’re doin' when you’re doin' what you look like you’re doin'!
         - Charles Wright & the Watts 103rd Street Rhythm Band