How do I persist Images with Doctrine

Deadly 提交于 2020-01-02 12:05:14

问题


I want to persist an Image in my Article Entity.

Is this possible with Doctrine2?

How do i do this?

Best Regards, bodo


回答1:


This is pretty simple using the ODM setup with the @File type.

For a ORM entity, I would look at creating a column like so.

NOTE: Use this link to add the blob type to Doctrine2

How add BLOB type in Doctrine 2 using Symfony 2

/** @ORM\Column(type="blob") */
protected $imageData;

/** @ORM\Column(type="string") */
protected $imageType;

/** @ORM\Column(type="int") */
protected $imageLength;

/** @ORM\Column(type="int") */
protected $imageWidth;

/** @ORM\Column(type="int") */
protected $imageHeight;

Then set that property with the raw data of the image. You will want to store things like the length, content-type, width and height along with the raw data so that you can create the right headers to retrieve the image and display it in the browser or download it.

That should be enough to get you started on the right path, or decide not to bother.



来源:https://stackoverflow.com/questions/9966940/how-do-i-persist-images-with-doctrine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!