Created
December 9, 2012 23:30
-
-
Save piscis/4247496 to your computer and use it in GitHub Desktop.
Basic Doctrine2 GridFS example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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