What's 'broken'? You mean you can't open it with adobe reader/other pdf viewer? If you check the contents of the file, does it look like a valid pdf?
On Tue, Mar 24, 2009 at 12:51, Tomasz Ignatiuk <[email protected]> wrote: > > Hi, I use this code for downloading files. If I download image, it > works, but if I download pdf, after downloading when I try to open it, > it is broken. > > if (is_file($sciezka)) > { > // Enforce full download and prevent > caching > session_cache_limiter('none'); > > // No layout needed for file downloads > $this->setLayout(false); > sfConfig::set('sf_web_debug', false); > > // Prepare http headers > $fileType = > $file->getFormat()->getNazwa(); > > $response = $this->getResponse(); > $response->clearHttpHeaders(); > $response->setHttpheader('Pragma: > public', true); > > $response->addCacheControlHttpHeader('Cache-Control', 'must- > revalidate'); > $response->setHttpHeader('Expires', > 'Sat, 26 Jul 1997 05:00:00 > GMT'); > > $response->setHttpHeader("Last-Modified", gmdate("D, d M Y > H:i:s") . " GMT"); > > $response->setContentType($fileType,true); > > $response->setHttpHeader('Content-Description', 'File Transfer'); > > $response->setHttpHeader('Content-Transfer-Encoding', 'binary', > true); > > $response->setHttpHeader('Content-Length', filesize('' . (string) > utf8_decode($sciezka . ''))); > > $response->setHttpHeader('Content-Disposition', 'attachment; > filename=' . str_replace(" ", "_", utf8_decode($file- >>getFileNazwaOrginalna())) ); > > // Unlock session in order to prevent > php session warnings > $this->getUser()->shutdown(); > > // Send http headers to user client > $response->sendHttpHeaders(); > > // Send file to user client > > //$response->setContent(readfile(utf8_decode($sciezka))); > > $response->setContent(readfile($sciezka)); > > //$response->setContent(file_get_contents(utf8_decode($file- >>getPath()))); > $response->sendContent(); > > // Exit without a template > return sfView::NONE; > > > This line gives a proper mime type > $response->setContentType($fileType, true); > > fileType is taken from DB. These are: application/pdf and image/jpeg > > It is strange because locally on apache on windows it works, but not > on production server. Locally when I upload file its pdf mime type is > application/x-download. On production server it is application/pdf > > Any ideas what is the problem? > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---
