user1239299
user1239299

Reputation: 817

Saving image as Doctrine2.3 blob data type

I have a class which I am trying to store an image as a blob data type, using the Doctrine2.3 as the orm.

/**
 * @ORM\Column(type="blob")
 */
private $data;

It says here that there is a doctrine mapping type called blob which maps a SQL BLOB to a php resource stream.When I build my data base from the class everything works fine. But when I try to insert a savedImage object into the database like this

$image = new SavedImage();
$data = fread(fopen($_FILES['data']['tmp_name'], 'r'), filesize($_FILES['data']['tmp_name'])); 
$image ->setData($data);
$this->entityManager->persist($image );
$this->entityManager->flush();

I get the following error :

json_encode(); Invalid UTF-8 sequence in argument.

Im not sure what is going wrong here any help would be appreciated.

Upvotes: 0

Views: 2449

Answers (1)

chakroun yesser
chakroun yesser

Reputation: 1497

add this line before setData($data);

$data= mb_check_encoding($data, 'UTF-8') ? $data: utf8_encode($data);

And for this a the link form more details

Upvotes: 1

Related Questions