in reply to Sending a file through STDOUT using HTTP

The correct way to set the content type and disposition is (untested)
print "Content-type: archive/zip\n" . "Content-Disposition: attachment; filename=$filename\n\n"; binmode STDOUT; $zip->writeToFileHandle( \*STDOUT, 0 );
There's a few points here:
  1. The correct way to set the content-disposition is with the filename= part but without the quotes around the filename (I think).
  2. With your current code you are trying to append the result of writeToFileHandle to your string. I think you mean ";" instead of "."
  3. writeToFileHandle expects a filehandle reference, not a string corresponding to the name of a filehandle.
  4. You should set binmode on a filehandle before writing binary data to it.
Give that a shot.

Replies are listed 'Best First'.
Re^2: Sending a file through STDOUT using HTTP
by TedYoung (Deacon) on Feb 18, 2005 at 00:51 UTC

    Good points! But, I did have to use the quotes around the file name in the past to handle files with spaces in their names.

    Ted Young

    ($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)
Re^2: Sending a file through STDOUT using HTTP
by Anonymous Monk on Feb 18, 2005 at 16:27 UTC
    Excellent points and I definitely appreciate the info. I now have:
    $zip->addTree( $path, '' ); print "Content-type: application/zip\n" . "Content-Disposition: attachment;filename=\"$filename\"\n\n"; binmode STDOUT; $zip->writeToFileHandle( \*STDOUT, 0 );
    Unfortunately the browser is still seeing it as a "httpd/unix-directory" and not getting a filename. I tried both with and without quotes on the filename. Any other ideas? Stupid MIME types...
      Sorry, forgot to login. The above post was me.
      I did a quick search on Google and it looks like the "httpd/unix-directory" think might be an Apache configuration issue. Are you sure your CGI code is actually getting executed? Maybe add something like print STDERR "My CGI called here" and see if that message shows up in your Apache error log.
        Well I'm pretty sure it gets called because the file does actually send. I printed to STDERR anyway and it showed up in the error_log correctly. Hmmm.