2009年5月20日星期三

[fw-mvc] Force download question

I'm trying to force file downloads and I'm running into a problem with
IE6 (this works in other browsers). Code for 3 tries is listed at the
bottom of this email. The first try works, but it's outside of ZF.
The other two tries are actions within a test controller. Try #2
doesn't really seem much different than try #1, but it doesn't work.

IE6 lists the wrong file name, the wrong file size, and the download
errors out - it says it wasn't able to open the website.

Any ideas why?

-Ed

--------------------------- Try #1
------------------------------------------------------------------------
<?php

header('Content-type: image/gif');
header('Content-Disposition: attachment; filename="Google_Logo.gif"');
readfile('http://www.google.com/logos/logo.gif');

?>


--------------------------- Try #2
------------------------------------------------------------------------

public function downloadGifAction() {
$this->getHelper('layout')->disableLayout();
$this->getHelper('ViewRenderer')->setNoRender();
header('Content-type: image/gif');
header('Content-Disposition: attachment; filename="Google_Logo.gif"');
readfile('http://www.google.com/logos/logo.gif');
}

--------------------------- Try #3
------------------------------------------------------------------------

public function downloadGifbAction() {
$this->getHelper('layout')->disableLayout();
$this->getHelper('ViewRenderer')->setNoRender();

$data = file_get_contents('http://www.google.com/logos/logo.gif');

$response = $this->getResponse()
$->setHeader('Content-Type', 'image/gif', true)
$->setHeader('Content-Disposition', 'attachment;
Filename="Google_Logo.gif"', true)
$->setHeader('Content-Transfer-Encoding', 'binary', true)
$->setHeader('Expires', 0)
$->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0')
$->setHeader('Pragma', 'public')
$->setHeader('Content-Length', strlen($data))
$->setBody($data)
$->sendResponse();
}

没有评论: