dongyongyin5339 2017-01-01 07:29
浏览 53

我如何通过php从mongodb播放ogg文件

I get the connection with mongodb in php. I can get the filename from the mongodb and display it in the webpage successfully. however, I cannot get the file recourse. if I get wrong , please remind me. thank you very much. I want to get the original file from the mongodb. I have mongodb php driver. someone can guide me? plz..

<?php
try{
    $connection = new Menter code hereongoClient();
    $db = $connection->FypDatabase;
    $grid = $db->getGridFS();
    $data = $grid->find();
    foreach($data as $obj){
        echo $obj->getFilename().'<br/>';
        echo $obj->getSize();
        echo $obj->getResource(); //it output the Resource id #2 
        echo '<video id="video" autoplay="autoplay" width="640" height="480" preload="metadata" >';
        echo '<source src="'.$data->getResource().'"/>';
        echo '<code>your bowser don\'t  support</code>';
        echo '</video>';
    }
    exit;
    $connection->close();
    } catch (MongoConnectionException $e) {
        die('Error connecting to MongoDB server');
    } catch (MongoException $e) {
        die('Error: ' . $e->getMessage());
    }
?>

I am trying to play the video in video tag. And get the video resource from the mongodb. In my mongodb, I have fs.chunks and fs.files collection. I do some research about the gridfs driver for php, it say,

MongoGridFSFile::getResource — Returns a resource that can be used to read the stored file

getResource() method

  • 写回答

1条回答 默认 最新

  • doulan8846 2017-01-01 07:34
    关注

    Maybe a typo : $obj->getResource() instead of $data->getResource()

    <?php
    try{
    $connection=new MongoClient();
    $db=$connection->FypDatabase;
    $grid=$db->getGridFS();
    $data=$grid->find();
       foreach($data as $obj){
        echo $obj->getFilename().'<br/>';
        echo $obj->getSize();
        echo $obj->getResource(); //it output the Resource id #2 
        echo '<video id="video" autoplay="autoplay" width="640" height="480" preload="metadata" >';
        echo '<source src="'.$obj->current().'"/>';
        echo '<code>your bowser don\'t  support</code>';
        echo '</video>';
        }
            exit;
            $connection->close();
    } catch (MongoConnectionException $e) {
      die('Error connecting to MongoDB server');
    } catch (MongoException $e) {
      die('Error: ' . $e->getMessage());
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题