Created
March 3, 2015 13:13
-
-
Save julienhay/be39447dcf15ca4553ff to your computer and use it in GitHub Desktop.
Froala action sf2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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