Skip to content

Instantly share code, notes, and snippets.

@MaximStrutinskiy
Last active January 25, 2017 11:03
Show Gist options
  • Save MaximStrutinskiy/51cb74b49fd2db40583b96fa3f8a1825 to your computer and use it in GitHub Desktop.
Save MaximStrutinskiy/51cb74b49fd2db40583b96fa3f8a1825 to your computer and use it in GitHub Desktop.
// if form is mapped => false;
$img = $form->get('img')->getData();
//if form is mapped => true
$img = $user->getImg();
if ($img !== NULL) {
// Generate a unique name for the file before saving it
$fileName = md5(uniqid()) . '.' . $img->getExtension();
// Move the file to the directory where brochures are stored
$img->move(
$this->getParameter('user_images'),
$fileName
);
// Update the 'img' property to store the img file name
// instead of its contents
$user->setImg($fileName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment