我的控制器中有这个功能来下载我存储在我的 mongodb 网格中的文件:
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 文件运行良好。谁能告诉我是什么问题?