LetMeKnow
2 days ago

Image not loaded using Ckeditor Upload image

Posted 2 days ago by LetMeKnow

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

Route::post('images/upload', '[email protected]')->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 ?

Please sign in or create an account to participate in this conversation.