Mongodb GridFS在下载.ppt和.doc文件时遇到问题


Mongodb GridFS having trouble downloading .ppt and .doc files?

我有这个函数在我的控制器下载文件,我存储在我的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文件可以正常运行。谁能告诉我出了什么问题?

嗯,经过一年的阅读,理解和实现PHP,我能够回答我自己的问题,我已经使用ob_clean()方法修复了错误,它像一个魅力,希望这有助于将来的人…

        $content= $object->getBytes();
        header("Content-Length: " . strlen($content)); 
        header($mimeType); 
        ob_clean(); 
        echo($content);