Я сохраняю файл через GridFS и сохраняю идентификатор, например так:
$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);
и через терминал и выполнение find () "file" возвращает: ObjectId ("4cbe9afe460890b774110000")
Если я сделаю это, чтобы создать канал JSON, чтобы я мог получить информацию о моем приложении, "файл" пуст ... почему это?:
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":{}}]