I'm trying to display a MEDIUMBLOB field of my database, which contain images, with Symfony 2 but I can't do it...
To do this, I created my own Doctrine type. Here is the code:
<?php
/**
* Personal type to support MediumBlob
*
* @author Leglopin
*/
namespace MC\UserBundle\Doctrine\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Types\Type;
/**
* Type that maps a PHP object to a mediumblob SQL type.
*/
class MediumBlobType extends Type
{
const MEDIUMBLOB = 'mediumblob';
public function getName()
{
return self::MEDIUMBLOB;
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform)
{
return $platform->getDoctrineTypeMapping('MEDIUMBLOB');
}
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
return ($value === null) ? null : base64_encode($value);
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return ($value === null) ? null : base64_decode($value);
}
}
Then, to display the image I'm doing this:
<img src="data:image/jpeg;base64,{{ photo }}">
where the photo variable is defined in my controller like this:
$photo = base64_encode($user->getPhoto());
But nothing is displayed
Thanks for your help !