public function executeDownloadFile(sfWebRequest $request) { $this->setLayout(false); $report = Doctrine::getTable('Reports')->find($request->getParameter('id')); if (!in_array($report->getName(), array_keys(Reports::getGlobalReports($this->getUser())))) { return $this->forwardToSecureAction(); } $this->forward404Unless(file_exists($uri = sfConfig::get('sf_upload_dir') . $report->getUri()), sprintf('This file does not exist')); $response = $this->getResponse(); // First clear HTTP headers $response->clearHttpHeaders(); // Then define the necessary headers $response->setContentType(Multimedia::getMimeTypeFor($report->getFormat())); $response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $report->getName() . "." . $report->getFormat() . '"'); $response->setHttpHeader('Content-Description', 'File Transfer'); $response->setHttpHeader('Content-Transfer-Encoding', 'binary'); $response->setHttpHeader('Content-Length', filesize($uri)); $response->setHttpHeader('Cache-Control', 'public, must-revalidate'); // if https then always give a Pragma header like this to overwrite the "pragma: no-cache" header which // will hint IE8 from caching the file during download and leads to a download error!!! $response->setHttpHeader('Pragma', 'public'); $response->sendHttpHeaders(); ob_end_flush(); return $this->renderText(readfile($uri)); }