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

Dear monks

I'm streaming an xls file, which works great, however the file is saved as 'process.pl'. Not really what I want, so I changed
print "Content-Type: application/vnd.ms-excel\n\n"
into
print header(-type=>'application/vnd.ms-excel', -attachment=>'overview.xls');
However, now I get an error and in the apache log I get
... malformed header from script. Bad header= : /opt/www/process.pl
Any suggestions what I'm doing wrong here ?

cheers
LuCa

UPDATE: thnx ahmad and Khen1950fx, it was a stupid mistake. The header stuff was copied from cpan, and in my case I have an $cgi object (I didn't show enought code :(

Replies are listed 'Best First'.
Re: cgi: malformed header from script. Bad header=
by ahmad (Hermit) on Jan 14, 2010 at 21:08 UTC

    I do not see anything wrong in the code you provided.

    Anyway, as written in CGI.pm documentation. You may have to use something like:

    -type => "application/octet-stream"

    for the attachment header to work.

    try it & let me know.

Re: cgi: malformed header from script. Bad header=
by Khen1950fx (Canon) on Jan 14, 2010 at 20:27 UTC
    I think it should be something like this:
    #!/usr/local/bin/perl use strict; use warnings; use CGI qw/:standard/; my $q= new CGI; print $q->header(-type => 'application/vnd.xls', -attachment => '/path/to/overview.xls');
      Ok, but there is no file, I'm streaming the xls