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

I'm building a system that gives authorized users access to protected documents. These documents are served through the perl script upon request via https. This script requires a valid login before serving such documents.

This script works fine for all of my binary files except for one: .eps files. Once the file is downloaded from a browser, graphic editing programs, such as photoshop, returning parsing errors. However, if I have the same script simply dump the data to a file on the server and then FTP the file to my computer, it works just fine. Obviously, there is an issue related to Apache's handling of the .eps data that is different than the other binary files.

Here is a simplified version of the script:


#!/usr/bin/perl -w use strict; my $dir = "/home/sitedirectory/document_repository/"; my $file = "company_logo.eps"; my $mimetype = "application/postscript"; open(FILE,"$dir$file"); binmode(FILE, ':raw'); my $output; my $buffer; while (read(FILE,$buffer,1024)) { $output .= $buffer; } my $length = length($output); print qq{Content-Disposition:attachment; filename="$file"\n\n}; print "Content-type: $mimetype\n\n"; print qq{Content-Length: $length\n\n}; print $output; exit;


Any help on this would be greatly appreciated!

Replies are listed 'Best First'.
Re: Print .eps files via https
by cjb (Friar) on Jan 23, 2012 at 16:43 UTC

    Code you please wrap your perl code in <code> tags?

    With regards to your problem, are you setting binmode on the output filehandle?

Re: Print .eps files via https
by Anonymous Monk on Jan 23, 2012 at 17:12 UTC

    Encapsulated PostScript documents aren't binary. Your programs may expect MSDOS linebreaks in them.

      Thanks for your help, guys. I found the problem. The header information after the first line was making its way into the beginning of the downloaded file. I removed the additional lines for that mime-type, and it's fixed.