Skip to content

Instantly share code, notes, and snippets.

@piscis
Created December 9, 2012 23:30
Show Gist options
  • Save piscis/4247496 to your computer and use it in GitHub Desktop.
Save piscis/4247496 to your computer and use it in GitHub Desktop.
Basic Doctrine2 GridFS example
/** @Document */
Class Image
{
/** @Id */
private $id;
/** @Field */
private $name;
/** @File */
private $file;
//....
// store file
$image = new Image();
$image->setName('Test image');
$image->setFile('/path/to/image.png');
$dm->persist($image);
$dm->flush();
// retrieve and return file to client
$image = $dm->createQueryBuilder('Documents\Image')
->field('name')->equals('Test image')
->getQuery()
->getSingleResult();
header('Content-type: image/png;');
echo $image->getFile()->getBytes();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment