Image source not readable in Laravel 5.2 - Intervention Image

前端 未结 6 1620
孤独总比滥情好
孤独总比滥情好 2021-02-07 18:27

I have a small problem concerning the resizing process of a given image, I am trying to submit a form containing an input type -->file<-- I was able to upload a picture witho

6条回答
  •  后悔当初
    2021-02-07 18:43

    This problem can also occur when you don't want to name the uploaded file using

    $filename = $file->getClientOriginalName();

    method. If you want to create your own uploaded file names, let's say, using the method below

    // $filename_without_ext = $request->input('name');
    $filename_without_ext = Str::slug($request->input('name'));
    $file_extension = pathinfo($logo->getClientOriginalName(), PATHINFO_EXTENSION);
    $filename =   time() . '-' . $filename_without_ext . '.' . $file_extension;
    

    If you use Laravel 5.8 and you get that error and you are trying to create your own file name, which is mostly necessary, you can fall into this trap. You should check the name field if it is coming as a form input. For example for the code above if you don't use the Str::slug function, which is a Laravel helper function, like the code with comments, you can run into problems because of the white space that the form field can have.

提交回复
热议问题