我通过GridFS存储一个文件并保存id,如下所示:
$file_id = $gridfs->storeUpload('texture');
$item = array(
'name'=>$_POST['name'],
'description'=>$_POST['description'],
'price'=>$_POST['price'],
'categories'=>$category_array,
'tags'=>$tag_array,
'file'=>$file_id
);
$collection->insert($item);
目标ID(“4cbe9afe460890b774110000”)
如果我这样做是为了创建一个JSON提要,这样我就可以为我的应用程序获取信息“file”是空的。。。这是为什么?:
foreach($cursor as $item){
$return[$i] = array(
'name'=>$item['name'],
'description'=>$item['description'],
'file'=>$item['file']
);
$i++;
}
echo json_encode($return);
foreach($cursor as $item){
echo $item['file'];
}
把它拿回来?
哦,以下是提要返回的内容:
[{"name":"Tea Stained Paper 1","description":"Grungy paper texture stained with tea and coffee.","file":{}},{"name":"Worn Metal 1","description":"A grooved, worn old metal texture","file":{}}]