COUPDEGRACES's avatar

Image not loaded using Ckeditor Upload image

Hi, i have a code route web.php like this

Route::post('images/upload', 'ImageController@upload')->name('ckeditor.upload');

and i have controller , i give name is ImageController

class ImageController extends Controller
{
    public function upload(Request $request)
 {
     if($request->hasFile('upload')) {
         $originName = $request->file('upload')->getClientOriginalName();
         $fileName = pathinfo($originName, PATHINFO_FILENAME);
         $extension = $request->file('upload')->getClientOriginalExtension();
         $fileName = $fileName.'_'.time().'.'.$extension;
        
         $request->file('upload')->move(public_path('images/'), $fileName);
   
         $CKEditorFuncNum = $request->input('CKEditorFuncNum');
         $url = asset('images/'.$fileName); 
         $msg = 'Image uploaded successfully'; 
         $response = "<script>window.parent.CKEDITOR.tools.callFunction($CKEditorFuncNum, '$url', '$msg')</script>";
               
         @header('Content-type: text/html; charset=utf-8'); 
         echo $response;
     }
}
}

in craete.blade.php

<script src="{{asset('ckeditor/ckeditor.js') }}"></script>
<script>
   CKEDITOR.replace('content', {
    filebrowserUploadUrl: "{{ route('ckeditor.upload', ['_token' => csrf_token() ])}}",
    filebrowserUploadMethod: 'form'
});
</script>

Now when im upload a image using button ckeditor , my post image in blog post not load a image , how i can fix it ?

0 likes
1 reply
bobbybouwmann's avatar

You shouldn't use the " around the route part because it's now being parsed as a string, not as PHP. Try this instead

<script>
    CKEDITOR.replace('content', {
        filebrowserUploadUrl: {{ route('ckeditor.upload', ['_token' => csrf_token()] )}
    });
</script>
2 likes

Please or to participate in this conversation.