I store the file through GridFS and save the id as follows:
$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 the terminal and the output, find () "file" returns: ObjectId ("4cbe9afe460890b774110000")
If I do this to create a JSON channel, so I can get information for my application. The file is empty ... 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 for me is why I can do:
foreach($cursor as $item){ echo $item['file']; }
and bring it back?
Oh, and this 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":{}}]
source share