0
A
回答
0
将它们保存在数据库中具有唯一名称和存储名称的文件夹中。
要上传图片,您可以在窗体中使用FileType字段,其文档为here。您可以使用将ImageType的表单验证我记得,这里是一些代码,将文件保存在文件夹中,并保存的文件名在数据库:
$user = new User();
$form = $this->createForm(UserForm::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$img = $user->getPhoto();
$fileName = md5(uniqid()).'.'.$img->guessExtension();
$user->setPhoto($fileName);
// Move the file to the directory where brochures are stored
$img->move(
$this->getParameter('user_image_directory'),
$fileName
);
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$em->flush();
}
而当你想要显示的IMG你显示它首先你用$ user-> getPhoto()读取文件名并将它发送到你的模板,当我从模板中调用user.getPhoto()时有一些错误,也许它只是我:
img src="{{ asset('media/users/') }}{{ filename }}"></div>
相关问题
- 1. resize facebook profile image
- 2. 用Image Magick识别profile-icc
- 3. 跨源图片加载(twitter profile image)
- 4. magento 2等效于Mage :: getModel('customer/customer') - > loadByEmail();是?
- 5. 在C#中,“Customer cust = new Customer()”是什么;“做?
- 6. Ws-basic profile 1.0 vs Ws-basic profile 1.1
- 7. Java - “(Customer)v.get(i)”做什么?
- 8. Customer Master - 联系人信息
- 9. Magento 1.7 - 删除/ customer/account/create/
- 10. Matlab`image(image)= - 1`?
- 11. .make与.profile
- 12. Sip Profile Building:Android
- 13. php profile with .htaccess
- 14. MVC Common Profile Class
- 15. Maven Profile for testing
- 16. Bash .profile not loading
- 17. @Profile和@ConditionalOnProperty
- 18. Liberty Profile + Servlet 2.4
- 19. OpenCV mat * image =(mat *)image
- 20. image/pjpeg和image/jpeg
- 21. background-image url response image
- 22. 正则表达式:在字符串'styles/customer.1031.css'中匹配'customer'
- 23. Bundle Identifier and Provisioning Profile
- 24. django-social-auth profile builder
- 25. Django - NoReverseMatch at/Profile/user
- 26. 有效的provisioning profile
- 27. CSS image-orientation:from-image;不工作
- 28. HTML Mouseover image over image推出
- 29. Android - ImageView Image Boundaries Bidder then Image
- 30. Image-> JSON - >。Net Image
显示您尝试过的操作(实施)以及您卡住的位置。为了改善您的问题,请阅读[我如何问一个好问题?](http://stackoverflow.com/help/how-to-ask)并相应地更新您的问题。 –
当然,我遵循[安装程序](https://github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/installation.md)没有任何问题,我想使用[yml映射](https: //github.com/dustin10/VichUploaderBundle/blob/master/Resources/doc/mapping/yaml.md)。这对教义没有影响:schema:update。 如果有必要我可以附加我的配置 –
是的,添加你的代码,看看你是如何实现它 –