Thanks again Lars. I finally got it to work. Seems that my final problem
was that I wasn't disabling the view, thereby corrupting the output. I
disabled my layout and set the view not to render, and I'm OK now.

Gina-Marie Rollock

-----Original Message-----
From: Lars Strojny [mailto:[EMAIL PROTECTED] 
Sent: Friday, August 15, 2008 6:09 PM
To: Gina-Marie Rollock
Cc: fw-general
Subject: Re: [fw-general] Downloading a file from server

Hi Gina-Marie,

Am Freitag, den 15.08.2008, 14:56 -0700 schrieb rollockg:
> I've been able to successfully upload a pdf file to my server, now I 
> want to reverse the process. I just have no idea how to go about it 
> using Zend Framework?

You do it in a very similar way as you would do it plain PHP: you send a
header, read the file, send the content of the file. So in a controller
it could looks something like this:

public function downloadAction()
{
    $this->getResponse()->setHeader('Content-Type: foo/bar');
    $filename =
$this->sanitizeFilename($this->getRequest()->getParam('filename'));
    $this->getResponse()->appendBody(file_get_contents($filename));
}

Note: the sanitizeFilename()-method is not present. You must implement
something like this to not introduce security issues where people can
download your /etc/passwd or something similar. But preferably such
validation is done in your domain model.
If you have a model and such file is part of your model, it could
probably look like that:

public function downloadAction()
{
    $model = new
YourDomainModel($this->getRequest()->getParam('filename'));
    $this->getResponse()->setHeader('Content-Type', $model->getType());
    $this->getResponse()->appendBody($model->getContent());
}

cu, Lars

Reply via email to