Thanks for the code. Here's what I tried and ran into the same
problem. Other browsers work (Safari and Firefox), but IE6 errors
out. It will display a prompt to save the file. The Name shows
"download-jpg". I click Save and then I get an error about not being
able to connect to the server. I'm copy / pasting the code. Does it
look like I did anything different? Also, I'm using ZF 1.7.5. I'm
not sure, but I don't think I can update to 1.8.1 on this particular
project right now as we're in the middle of launch and I think the
upgrade would bring up other issues. Which version of ZF are you on?
-Ed
public function downloadJpgAction() {
$data = @file_get_contents(Zend_Registry::get('rootdir').'/htdocs/Images/Brian_Henninger.jpg');
$response = $this->_response;
if (strlen($data) == 0) {
$response->setBody("Sorry, we could not find the requested download file.");
} else {
$response->setHeader('Content-type','image/jpg', true);
$response->setHeader('Content-Type','application/octet-stream', true);
$response->setHeader('Content-Disposition','attachment;
filename="Brian_Henninger.jpg"', true);
$response->setHeader('Content-length',strlen($data), true);
$response->setBody($data);
}
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
}
On Wed, May 20, 2009 at 8:29 AM, <lionel@morrison101.com> wrote:
> Hi Ed,
>
> Just dealt with a similar issue. Try this.
>
> $bits =
> @file_get_contents(Zend_Registry::get('rootdir').'/application/data/'.$data['uuid']);
>
> $response = $this->_response;
>
> if(strlen($bits) == 0) {
> $response->setBody('Sorry, we could not find requested download
> file.');
> }
> else {
> $response->setHeader('Content-type',$data['type'], true);
> $response->setHeader('Content-Type','application/octet-stream',
> true);
> $response->setHeader('Content-Disposition','attachment;
> filename='.$data['filename'], true);
> $response->setHeader('Content-length',$data['size'], true);
>
> $response->setBody($bits);
> }
>
> You might also need to to use the following:
> $this->_helper->layout()->disableLayout();
> $this->_helper->viewRenderer->setNoRender(true);
没有评论:
发表评论