Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. <form role="form" id="contact_form" class="contact-form" method="post" action="{{ path('publier_offre') }}">
  2. <input type="file" class="form-control" name="" id="imageOffre">
  3. </form>
  4.  
  5. and this the controller action ( where to get the uploaded image and persisting it to the database ) :
  6. public function publierOffreAction(Request $request)
  7. {
  8. if($request->isMethod('POST')){
  9. $offre = new offre();
  10. //getting the image file
  11. $filename = $request->get('imageOffre');
  12. $filename->move(
  13. $this->getParameter('image_directory'),$filename
  14. );
  15. $offre->setImage($filename);
  16. //getting the image file
  17. $em=$this->getDoctrine()->getManager();
  18. $em->merge($offre);
  19. $em->flush();
  20. }
  21. return $this->render('@offer/Default/publieroffre.html.twig');
  22. }
  23.  
  24. /**
  25. * @var string
  26. * @AssertNotBlank(message="plz enter an image")
  27. * @AssertImage()
  28. * @ORMColumn(name="image", type="string", length=255)
  29. */
  30. private $image ;
  31.  
  32. /**
  33. * @return string
  34. */
  35. public function getImage()
  36. {
  37. return $this->image;
  38. }
  39.  
  40. /**
  41. * @param string $image
  42. */
  43. public function setImage($image)
  44. {
  45. $this->image = $image;
  46. }
  47.  
  48. parameters:
  49. locale: en
  50. image_directory: '%kernel.project_dir%/web/uploads/images'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement