in reply to Cgi params as binary data

Your question is a little unclear to me. When something isn't clear to me, I start debugging and debug until it is clear. What I tried here was to pass the params to the filehandle. It'll save the data without putting on the disk. You need to binmode the filehandle in order for it to work; also, you need to call the new method twice. Carp and CGI::Carp::DebugScreen are required.
!/usr/bin/perl use warnings; use Carp; use CGI qw(param); use CGI::Carp::DebugScreen; open( OUT, '>>/root/Desktop/zip.out' ); CGI::Carp::DebugScreen->debug(1); my $q = CGI->new; binmode OUT, ':raw'; my $name = $q->param('content_of_zip') || "Content"; my $out = $q->param('output') || "Binary"; $q->save(OUT); close OUT; # now double-check to see if it was saved. open( IN, '/root/Desktop/zip.out' ); while ( not eof IN ) { $q = CGI->new; print $name, "\n", $out, "\n"; exit 0; } close IN;

Replies are listed 'Best First'.
Re^2: Cgi params as binary data
by Anonymous Monk on Jun 05, 2011 at 09:22 UTC
    also, you need to call the new method twice.

    you don't need to do it in a loop

      alright, I'm being unclear. I'll try to be simple

      1. user uploads zip in a form

      2. on form submit (action=site.cgi) zip is processed using some external program

      3. the output of the external program can be either a zip or HTML (raw output, not a file)

      4. if I just do "print $my_program_output", the html output will reload/replace the page, but the zip will just present a zip file for download without reloading the page behind it (this works fine, without having to write the output to a file)

      here's my problem: In the case of the zip file, I want to refresh the original page (or have access to its content with javascript), but I don't know how to do that. And I want to avoid having to open a new file and write to it.

        here's my problem: In the case of the zip file, I want to refresh the original page (or have access to its content with javascript), but I don't know how to do that. And I want to avoid having to open a new file and write to it.

        Can you explain that in terms of HTTP?