0

I want to perform an image upload with Symfony2.

I followed the cookbook entry but failed so I firstly used the fallback "upload directly in the controller" but here's the same issue.

I am getting

Notice: Undefined property:  Symfony\Component\Form\Form::$getData in 

The controller isValid() part:

            if ($form->isValid()) {
            $em = $this->getDoctrine()->getEntityManager();

            $filename = uniqid('class_photo') . '.' . $photo->getFile()->guessExtension();
            $directory = __DIR__ . '/../../../../web/';
            $form['file']->getData->move($directory, $filename);
            $photo->setFile(null);
            $photo->setPath($directory . $filename);

            $em->persist($photo);
            $em->flush();
//....
}

Best Regards, Bodo

1 Answer 1

1

This:

$form['file']->getData->move($directory, $filename);

Should probably be:

$form['file']->getData()->move($directory, $filename);

But I think you would be better off figuring out why the cookbook example did not work for you. once a form has been validated you really should not need to go back in to it.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, I figured it out the issue was that I left $form->upload() in the controller even the entity now handles the upload

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.