Note that there are some explanatory texts on larger screens.

plurals
  1. POPERL CGI: Filehandle that uses both binary and text mode
    text
    copied!<p>I have a perl program that writes application/zip document with binary data. I can do the following code in my cgi script. </p> <pre><code>print $cgi-&gt;header(-type=&gt;"application/x-zip; name=\"$filename.zip\"", -content_disposition=&gt; "attachment; filename=\"$filename.zip\""). "\n"; print $result </code></pre> <p>where <code>$result</code> is the binary data. This will then output a page that prompts the user to download the zip</p> <p>What I want to do though is pass that entire 'webpage' as form parameter, so I did this: </p> <pre><code>open $resultfh, "&gt;", \$output_buffer or die "could not open buffer"; print $resultfh $cgi-&gt;header(-type=&gt;"application/x-zip; name=\"$filename.zip\"", -content_disposition=&gt; "attachment; filename=\"$filename.zip\""). "\n"; print $resultfh $result </code></pre> <p>and then I can pass the <code>$output_buffer</code> around as variable. </p> <p>The problem is that this doesn't work, <em>something</em> seems to get passed because I'm prompted to download the zipfile, but the zipfile is corrupted, I get a mismatch between the expected bytes and the actual bytes or something. </p> <p>I <em>think</em> this has to do with that output buffer not being in binary mode, but I can't read the content header in binary mode, so can I have a file handle be partially in text and partially in binary?</p> <p>If not, what options do I have?</p> <p><strong>EDIT:</strong> The problem actually seems to happen when I pass the binary data as a cgi form param. Anyone know what the problem might be? Maybe a size limit? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload