Вы должны иметь отдельное действие, которое знает, как извлечь и доставить все эти вещи. Что-то вроде этого:
public function viewpdfAction()
{
$id = (int) $this->_getParam('id', 0);
// You implement some function - either here in your controller
// or someplace else - to get the pdf name from the passed id.
// Alternatively, you can pass the name itself. Up to you, of course.
// The key is that the request somehow identifies the file requested.
$pdfName = $this->_mapPdfIdToName($id);
// The path to the real pdf
$pdfFile = '/project/data/uploads/pdf/' . $pdfName;
// Disable rendering
$this->_helper->viewRenderer->setNoRender(true);
// Send the right mime headers for the content type
$this->getResponse()
->setBody('')
->setHeader('Cache-control', 'public') // needed for IE, I have read
->setHeader('Content-type', 'application/pdf')
->setHeader('Content-Disposition', sprintf('attachment; filename="%s"', $pdfName));
// Send the content
readfile($pdfFile);
}
Конечно, некоторые из этого можно сдвинуть вниз на классы обслуживания, чтобы держать контроллер как можно тоньше. В этом отношении у всех разные вкусы.
Признаюсь, что этот код не полностью протестирован, в основном пытается дать основную идею. Если у меня есть общая ошибка в кости, пожалуйста, дайте мне знать.
Надеюсь, это поможет!
Правильно ли вы установили права на свои папки для загрузки? – Marcin