I'm storing a file through GridFS and saving the id like so:
$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);
and through terminal and doing find() "file" returns: ObjectId("4cbe9afe460890b774110000")
If i do this to create a JSON feed so i can get info back for my application "file" is blank... why is this?:
foreach($cursor as $item){
$return[$i] = array(
'name'=>$item['name'],
'description'=>$item['description'],
'file'=>$item['file']
);
$i++;
}
echo json_encode($return);
The strange thing, to me, is why can I do:
foreach($cursor as $item){
echo $item['file'];
}
and get it back tho?
Oh, and here is what the feed returns:
[{"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":{}}]