当我使用ckeditor
上传图像时。我收到此错误。
edit.blade.php
CKEDITOR.replace('body', {
filebrowserUploadUrl: "{{route('upload', ['_token' => csrf_token() ])}}",
filebrowserUploadMethod: 'form',
extraPlugins: 'easyimage',
cloudServices_tokenUrl: 'http://localhost:8000/admin/ckeditor/image-upload',
cloudServices_uploadUrl: 'http://localhost:8000/admin/ckeditor/image-upload'
});
web.php
Route::namespace('Admin')->prefix('admin')->group(function (){
Route::get('dashboard', 'DashboardController@dashboard')->name('dashboard.index');
Route::get('ckeditor/image-upload', 'DashboardController@upload')->name('upload');
DashboardController.php
public function upload(Request $request)
{
$this->validate(request() , [
'upload' => 'required|mimes:jpeg,png,bmp',
]);
$year = Carbon::now()->year;
$imagePath = "public/upload/images/{$year}/";
$file = request()->file('upload');
$filename = $file->getClientOriginalName();
if(file_exists(public_path($imagePath) . $filename)) {
$filename = Carbon::now()->timestamp . $filename;
}
$file->move(public_path($imagePath) , $filename);
$url = $imagePath . $filename;
return "<script>window.parent.CKEDITOR.tools.callFunction(1 , '{$url}' , '')</script>";
}
当我在web.php中更改
我再次看到此错误
Route::post('ckeditor/image-upload', 'DashboardController@upload')->name('upload');