我有這個功能在我的控制器下載,我很存儲在我的MongoDB的網格文件:Mongodb GridFS無法下載.ppt和.doc文件?
function download_presentation($ext,$store_filename)
{
$grid = $this->mongo->db->getGridFS();
//query the file object
$objects = $grid->find();
//set content-type header, output in browser
switch ($ext) {
case 'pdf':
$mimeType = 'Content-type: application/pdf';
break;
case 'jpg':
$mimeType = 'Content-type: image/jpg';
break;
case 'png':
$mimeType = 'Content-type: image/png';
break;
case 'doc':
$mimeType = 'Content-type: application/msword';
break;
case 'docx':
$mimeType = 'Content-type: application/vnd.openxmlformats-officedocument.wordprocessingml.document';
break;
case 'xls':
$mimeType = 'Content-type: application/vnd.ms-excel';
break;
case 'xlsx':
$mimeType = 'Content-type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
break;
case 'ppt':
$mimeType = 'Content-type: application/x-mspowerpoint';
break;
case 'pptx': $mimeType = 'Content-type: application/vnd.openxmlformats- officedocument.presentationml.presentation';
break;
default:
$mimeType='Content-type: application/pdf';
}
while($object = $objects->getNext()) :
if(($object->file['filename'])==$store_filename){
$content=$object->getBytes();
header("Content-Length: " . strlen($content));
header($mimeType);
echo ($content);}
endwhile;
} 每當我下載.PPT跟它怎麼一回事,因爲它是PowerPoint無法打開此文件中的文件不是.ppt。對於pptx文件,當我打開它下載後,它正在工作,當我點擊'修復'從PowerPoint中彈出。所有的事情都與.doc/MS-Word一起發生。只有pdf文件運行完美。 任何人都可以請告訴我什麼是問題?
嘗試調用$對象 - > [的getSize(http://mongodb.github.com/node-mongodb-native/api-articles/nodekoarticle1.html)而不是使用strlen函數。 – WiredPrairie