文件上传期间发生HTTP错误(404:找不到文件)

时间:2019-05-29 20:32:54

标签: laravel-5.8

CKEditor上传图像不起作用当我上传图像时,我看到此错误。

  

文件上传期间发生HTTP错误(404:找不到文件)。

我在控制台中看到此错误

ckeditor

web.php

Route::post('/images', 'DashboardController@uploadImageSubject');

DashboardController.php

public function uploadImageSubject()
{
    $this->validate(request() , [
        'upload' => 'required|mimes:jpeg,png,bmp',
    ]);

    $year = Carbon::now()->year;
    $imagePath = "/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>";
}

0 个答案:

没有答案