[Solved] How to upload file using ajax/jQuery with Symfony2


Firstly, I notice that your click event for #upload_image fires a click trigger on #bundle_user_file, but below that you are asking it to look for a change event. Therefore, this would do nothing.

You can re-generate a CSRF token if you want by calling the csrf token_manager service by doing this:

/** @var \Symfony\Component\Security\Csrf\CsrfTokenManagerInterface $csrf */
$csrf = $this->get('security.csrf.token_manager');
$token = $csrf->refreshToken($tokenId);

return new Response($token);

You can determine $tokenId in your form, if you want, or just use your picture ID, or whatever. Normally the CSRF token is generated automatically from your session, so you might want to check that too.

solved How to upload file using ajax/jQuery with Symfony2