I've been trying to setup file upload via default symfony form and Symfony\Component\HttpFoundation\File\UploadedFile. I have really trivial form, with one input, button for file upload and submit button. Here is my conroller:
class DefaultController extends Controller
{
public function uploadAction(Request $request)
{
$document = new Elements();
$form = $this->createFormBuilder($document)
->add('name')
->add('file')
->add('save', SubmitType::class, array('label' => 'Create Task'))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$document->upload();
$em->persist($document);
$em->flush();
return $this->redirectToRoute('felice_admin_upload');
}
return $this->render('FeliceAdminBundle:Default:upload.html.twig', array(
'form' => $form->createView(),
));
}
}
And I have also created an entity, to persist data to database. I'm using doctrine. Everything that I did, was by manual: http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html
But the only exception was that I used yml, not annotations. After all, I have an error, when trying to upload file:
FileNotFoundException in File.php line 37: The file "/tmp/phpFMtBcf" does not exist
What I am doing wrong?