You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "John N. Brahy" <jb...@ad2.com> on 2006/03/02 19:46:09 UTC
Content Disposition header and file contents sequence...
This is the relevant part of my handler for a link that I want to force
a download for. I know it's content-disposition but for some reason I
can not get it to actually download the file. I get the download dialog
and I choose the location to save it but when I open the document it is
empty. I've tried changing the sequence of the items but it never works.
my $filename = "/usr/local/app/media/videos/downloads/preview.mov";
unless ($fileFH = Apache::File->new($filename)){
$r->log_error("couldn't open $filename for reading: $!");
return SERVER_ERROR;
}
$r->content_type('video/quicktime');
$r->headers_out->set('Content-Disposition' =>
"attachment;filename=$downloadFilename");
$r->send_fd($fileFH);
$r->send_http_header();
return OK;
::::: John Brahy
::::: CIO
::::: www.ad2.com
::::: johnb@ad2.com
::::: t: 310-356-7500
::::: f: 310-356-7520
::::: ad2, Inc.
::::: 1990 East Grand Ave, Suite 200
::::: El Segundo, CA 90245
Re: Content Disposition header and file contents sequence...
Posted by Geoffrey Young <ge...@modperlcookbook.org>.
> $r->headers_out->set('Content-Disposition' =>
> "attachment;filename=$downloadFilename");
try
$r->headers_out->set('Content-Disposition' => ' inline;
filename=$downloadFilename');
> $r->send_fd($fileFH);
> $r->send_http_header();
those definitely need to be reversed - you need to send the headers before
you send any output.
--Geoff