I want to upload an image to Ckeditor, but when I upload it to the text editor, I can’t
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('media'), $fileName);
$url = asset('media/' . $fileName);
return response()->json(['fileName' => $fileName, 'uploaded'=> 1, 'url' => $url]);
}
}
<script>
ClassicEditor
.create(document.querySelector('#body'), {
ckfinder: {
uploadUrl: "{{ route('ckeditor.upload', ['_token' => csrf_token()]) }}",
}
})
.catch(error => {
console.error(error);
});
</script>
Route::post('ckeditor/upload', [ProfileController::class, 'upload'])->name('ckeditor.upload');
I want the images I upload to appear in the blog details
New contributor