We’re trying to send uploaded attachements (served from a database as blob) through php with Zend Framework to a client.
This code works fine for Excel97 / Word97.
if ($this->getResponse()->canSendHeaders(false)) {
$response = $this->getResponse();
$response->setHeader('Pragma', 'public', true)
->setHeader('Expires', '0', true)
->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
->setHeader('Content-Type', 'application/force-download', true)
->setHeader('Content-Type', 'application/octet-stream', true)
->setHeader('Content-Type', 'application/download', true)
->setHeader('Content-Disposition', "attachment;filename=$filename", true)
->setHeader('Content-Transfer-Encoding', 'binary', true)
->setBody($data) // binary
->sendHeaders();
}
But is not working for excel2007 / word2007. It reports “file has an error” and trys to fix it.
Any suggestions?
You should send the correct
Content-Typefor the given file format. That should beapplication/msword/application/vnd.ms-excelif you’re sending old.doc– or.xls-files andapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentorapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetfor the newerx-type files.docxand.xlsxrespectively (don’t know which version you’re serving).Further more, as far as I know, the newer Office programs check if the file extension matches the file content, so you’ll get errors or warnings when opening
.doc-files with an.docx-extension.A
...->setHeader('Content-Type', '<<the appropriate content-type>>', true)should be sufficient.