CGI download/BinMode issue

Problems with the Windows version of XAMPP, questions, comments, and anything related.

CGI download/BinMode issue

Postby systemz » 06. January 2007 18:05


not sure what is going on here. I have a standard xampp install on win XP, with the updated install of perl - which is activeperl 5.8.8. I have some test code to send a pdf from the cgi to the browser as follows:

#!C:/Program Files/xampp/perl/bin/perl

print "Content-Type:application/pdf\n";
print "Content-Disposition:attachment;filename=test3.pdf\n\n";

my $files_location;
my $ID;
my @fileholder;

$files_location = "C:\Data\Perl";

open(DLFILE, "<$files_location\test.pdf");
@fileholder = <DLFILE>;
close (DLFILE);

print @fileholder;


When I run this, I get the save as dialog. Whether I save or open directly, the resulting data is deemed as corrupt by acrobat. If I access the file directly via apache rather than the cgi, it works fine. To make sure the code was OK, I ran the same code (apart from the paths and the binmode) on a unix install - and it worked fine. I also tried an equivalent version of PHP via the xampp install - worked fine. So this seems to be a perl issue on win32.

Has anyone got a clue as to what the problem could be?


Posts: 2
Joined: 06. January 2007 17:59

Postby Dave_L » 06. January 2007 22:38

@fileholder = <DLFILE>;

That reads the lines of a file into an array, which makes sense for a text file, but not for a binary file such as a .pdf, which doesn't contain "lines".

I would use something like this for a binary file:

Code: Select all
use constant BUFFER_SIZE => 16 * 1024;

binmode DLFILE;
binmode STDOUT;

my $buffer = '0' x BUFFER_SIZE;
while (read(DLFILE, $buffer, BUFFER_SIZE)) {
   print $buffer;

Also, you should use forward slashes (/) as path delimiters, not backward slashes (\).

The HTTP headers might need modification too, but try the above changes first.
User avatar
Posts: 212
Joined: 23. October 2004 00:43

Postby systemz » 07. January 2007 17:39

Thank you. Problem solved.

Posts: 2
Joined: 06. January 2007 17:59

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 62 guests