Reputation: 653
I'm currently coding a symfony app, and i'm having trouble with the Imperavi Redactor image upload.
Redactor loads fine for texteareas in my usual forms all over the website, but i can't make the uploading work.
I call Redactor in my "base.html.twig" with this code :
$('.redactor').redactor({
plugins: ['fullscreen'], });
This code works fine to load and edit the text. It works as well to use internet images, but i want to use the live upload setting that made me choose this editor. And the docs ask me to add a
imageUpload : "/image/upload.php"
But as i'm using symfony i have a :
imageUpload : Routing.generate('bdl_appli_appli_imageupload')
That should work fine. (js-routing works fine elsewhere in the website) I then added the code from the website in my controller:
public function imageUploadAction() {
$dir = 'C:/wamp/www/bdl-capital/web/upload/images/';
$_FILES['file']['type'] = strtolower($_FILES['file']['type']);
if ($_FILES['file']['type'] == 'image/png' || $_FILES['file']['type'] == 'image/jpg' || $_FILES['file']['type'] == 'image/gif' || $_FILES['file']['type'] == 'image/jpeg' || $_FILES['file']['type'] == 'image/pjpeg') {
// setting file's mysterious name
$file = $dir.md5(date('YmdHis')).'.jpg';
// copying move_uploaded_file($_FILES['file']['tmp_name'], $file);
// displaying file $array = array( 'filelink' => '/images/'.$file );
$response = new JsonResponse(); $return $response->setData($array);
}
However, this does not work, and i'm looking for any advice.
I found this bundle : https://github.com/AStepanov/RedactorBundle
But it hasn't been updated for a year now, and i tried it without success, the redactorType is not updated to symfony 2.4... I tried to use the service alone but still no clue...
Has anyone managed to do this properly ? Can i use a pure PHP file within my symfony app just for this section ? I'm ready to have this tiny bit of code in pure php but i really have to make it work...
Upvotes: 1
Views: 1968
Reputation: 653
To anyone trying to get to the same result, i managed to find an updated version of the bundle : https://github.com/kraksoft/RedactorBundle/network
I made my own version based on it and even managed to make the copy&paste from clipboard work, and will try to update my own bundle at the beginning of summer here : https://github.com/florentdestremau/RedactorBundle Feel free to ask for it if you need it now
Upvotes: 1