Skip to content

Instantly share code, notes, and snippets.

@julienhay
Created March 3, 2015 13:13
Show Gist options
  • Save julienhay/be39447dcf15ca4553ff to your computer and use it in GitHub Desktop.
Save julienhay/be39447dcf15ca4553ff to your computer and use it in GitHub Desktop.
Froala action sf2
/**
* @Route("/upload_image_wysiwyg", name="upload_image_wysiwyg", options={"expose"=true})
*/
public function uploadImageWYSIWYGAction(Request $request)
{
$user = $this->getLoggedUser();
if(!$user)
{
return new JsonResponse(array('success'=>false,"error"=>"bad request"));
}
$extensions = array('png','jpg','jpeg','gif','bmp');
$dir_path = 'medias/wysiwyg_files/';
$uploadedFile = $request->files->get('file');
$response = new \StdClass;
if ($uploadedFile)
{
$ext = $uploadedFile->guessExtension();
if(in_array($ext, $extensions))
{
$file = $uploadedFile->move('../web/'.$dir_path, $uploadedFile->getClientOriginalName());
if($file)
{
// Generate response.
$response->link = '/'.$dir_path.$uploadedFile->getClientOriginalName();
}
}
}
return new JsonResponse($response);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment