Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

cgi post to return file

by Anonymous Monk
on Apr 07, 2002 at 04:10 UTC ( #157229=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I have searched the many cgi questions and because this one isn't there, it proably won't make sense ;-) but here goes:

I got POST and my form working. I like that I can pass some parameters to the form, like name/email, and then use them in the cgi script...

Now I want to change my GET to do the same thing. Do I want to pass name/email in a POST form?

Right now the GET code does a
my $res = $ua->request($req, $file);
to save the file...I need to emulate this, as I don't want POST to return a file that the user will get the "open/save" file box...

thanks for any suggestions!

(Part of my confusion is that GET doesn't *seem* to execute a script...I have a script and would like a one also)

Replies are listed 'Best First'.
Re: cgi post to return file
by grep (Monsignor) on Apr 07, 2002 at 05:03 UTC

    Ok I'm taking a stab at this. I'm not answering your specific questions, but I guessing at what you are really trying to accomplish

    Ok I will assume you are using if not you should be.

    It sounds like you want to give the end user the ability to upload and download files. To allow the user to download a file just use an anchor tag with an href <a href="your_file.tgz">your file</a>

    To handle the end use uploading a file use the multipart start_multipart_form() to start the form, then create a filefield input

    print $query->filefield(-name=>'uploaded_file', -default=>'starting value', -size=>50, -maxlength=>80);

    On the receiving script end just access the param

    # Read a text file and print it out while (<$filename>) { print; } # Copy a binary file to somewhere safe open (OUTFILE,">>/usr/local/web/users/feedback"); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; }

    There are some security concerns whenever you allow users to upload files. I would recommend using CGI::Safe and also looking at the author of CGI::Safe's CGI course

    Also I do not believe GET will handle multipart forms

    all code in this post was taken from the POD available on

    grep> cd /pub
    grep> more beer
      I knew is was confusing ;-) probably because I left important "stuff" out...

      I am using CGI and I got the file upload working correctly. I am also using LWP (probably important to mention, as this is NOT user interactive w/broswer).

      My goal is to pass username and email parameters to the cgi script "" and then have the cgi script pass back the file, which I programatically do some stuff with...

      I can use HTTP::Request::Common to use GET() just fine (I used POST() for the above But I don't think I can pass the 2 parameters to the server by using GET()...I know that POST() allows you to set parameters though...

      This code looks good to save the file...but I think the "anchor tag" will only work with the broswer...correct ?
      # Copy a binary file to somewhere safe open (OUTFILE,">>/usr/local/web/users/feedback"); while ($bytesread=read($filename,$buffer,1024)) { print OUTFILE $buffer; }
      Thanks again ;-)
        I can think of 2 solutions.
      • You can redirect UserAgent to the file (this would be the easiest way)
      • else you can try a server push. I have never tried this the UserAgent

      • grep
        grep> cd /pub
        grep> more beer
Re: cgi post to return file
by Hero Zzyzzx (Curate) on Apr 07, 2002 at 04:23 UTC

    You're right. It doesn't make sense. I have no idea what you're talking about. Can you please clarify? Are you using CGI for parsing your form parameters?

    -Any sufficiently advanced technology is
    indistinguishable from doubletalk.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://157229]
Approved by cjf
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-10-17 05:10 GMT
Find Nodes?
    Voting Booth?