php - 交响乐 2 : How do I manually assign a file to an entity which has been configured to use VichUploaderBundle to handle file uploads

标签 php symfony gaufrette vichuploaderbundle

我已经设置了 VichUploaderBundle 以便于为我的用户实体上传个人资料图像。我正在使用 GaufretteStorage 选项,配置为使用本地文件系统,当用户通过表单上传图像时一切正常。

我现在希望能够自己在代码中将个人资料图像文件分配给用户实体,而不是依赖用户通过表单上传。我该怎么做?

我希望我说得够清楚了......基本上我有一个图像文件的内容(我可以通过 file_get_contents() 或类似的措施获取)并且我想将这个文件分配给用户个人资料图像属性。

最佳答案

在联系了 bundle 的维护者之后,他提供了这个解决方案来回答我的问题:

Have a look at this https://github.com/dustin10/VichUploaderBundle/pull/200/files

Keep in mind that the bundle is triggered by entity lifecycle events (onPersist onLoad etc), but it will only manage the copy if an instance of UploadedFile is injected in the entity.

if you want to manually create the file but still manage it with the bundle you'll have to inject and UploadedFile in the entity.

关于php - 交响乐 2 : How do I manually assign a file to an entity which has been configured to use VichUploaderBundle to handle file uploads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22097541/

相关文章:

php - Goutte-dom爬虫-移除节点

symfony - 如何使用 symfony/gauferette/VichUploaderBundle 将文件上传到 Google Cloud Storage

php - 如何使用 Gaufrette 和 Symfony 3.0

php - 将单列查询值拆分为不同的 php 变量

php - Symfony Elasticsearch配置文件不适用于多种类型的1个索引

php - 将mysql中的行数显示到android中的textview中

php - 可捕获的 fatal error : Object of class __PHP_Incomplete_Class could not be converted to string

php - 获取使用 "group by"检索的正确行值

php - 解析包含 3 个分隔符的格式化字符串以创建多个平面数组