Can't upload file via Symfony 2.8 form upload
Ok, I'm still haven't found an answer for my question. I've tried to search on different forums, in on French :) So my solutions in next. I gather file data manually, before actually handling a request, then I handle a request and next thing what I do, is I copy my file instead of moving. That is not getting my described error. So it should be quite refactored for beauty and convenience, but it works well. Thank you for attention.
class DefaultController extends Controller{/** * @Route("/product/new", name="app_product_new") */public function newAction(Request $request){ $product = new Product(); $form = $this->createFormBuilder(null, array('csrf_protection' => false)) ->add('pic', FileType::class, array('label' => 'Picture')) ->add('Send', 'submit') ->getForm(); $pic = $request->files->get("form")["pic"]; $form->handleRequest($request); if ($form->isValid()) { // $file stores the uploaded PDF file /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */ $file = $pic; // Generate a unique name for the file before saving it $fileName = md5(uniqid()) . '.' . $pic->guessExtension(); // Move the file to the directory where brochures are stored $brochuresDir = $this->container->getParameter('kernel.root_dir') . '/../web/uploads'; copy($pic->getPathname(), $brochuresDir . "/" . $fileName); // Update the 'brochure' property to store the PDF file name // instead of its contents $product->setPic($fileName); // ... persist the $product variable or any other work return $this->redirect($this->generateUrl('app_product_new')); } return $this->render('FeliceAdminBundle:Default:index.html.twig', array( 'form' => $form->createView(), ));}}