我可以通过GridFS成功上传/下载Mongodb中的图像文件,但是当我尝试上传mp3文件时,没有任何反应。我没有收到任何错误,也没有上传任何错误,我进一步检查了文件的权限,它与那些图像文件非常相似,加上文件大小也不算太大,只有6mb左右。但由于未知原因,它不会通过GridFS与php上传到Mongodb数据库中。请帮我把MP3文件加载到数据库。用于上传文件的代码如下:
<?php
error_reporting(0);
$m = new MongoClient();
$gridfs = $m->selectDB('mydb')->getGridFS();
$gridfs->storeUpload('pic', array('_id'=>$_POST['_id'],'Username' => _POST['username'] ));
echo 'File Uploaded Successfully';
?>
答案 0 :(得分:0)
而不是storeUpload使用storeFile,如下面给出的示例 例如:
<?php
// connect to the ‘myGrid’ GridFS
$m = new Mongo();
$db = $m->myDB;
$myGrid = $db->getGridFS('myGrid');
$some_file='path of your video or audio file';
// some extra data you may want to store with your file
$data_array = array(
'mime' => mime_content_type($some_file),
'timestamp' => time(),
);
// store a file into the GridFS
$myGrid->storeFile($some_file, $data_array);
?>