user image

Jo Micheal
Published in : 2021-12-19

Symfony\Component\Mime\Exception\InvalidArgumentException: The "" file does not exist or is not readable.

Laravel

Symfony\Component\Mime\Exception\InvalidArgumentException: The "" file does not exist or is not readable. this error came to my website when I try to upload files using Laravel Storage class with jQuery ajax, here is the code which I am using

 public function uploadImageAjax(Request $req){ if($req->image){ $image_name = basename( Storage::disk('public')->put('products/', $req->image)); $link = url('/').'/storage/products/'.$image_name; return $link; } }

Can anyone help me please?

Comments

Joseph Morgan Date : 2021-12-19

Best answers

11

Best answers

11

That's because the maximum value of the uploading in your server is less than the size of the image, so you can increase the size of uploading in your php.ini, you will need to locate the php.ini file in your server using phpinfo(); you can use a simple routing with the function like this,

Route::get('/php', function(){ phpinfo(); return false;});

you can search about "Loaded Configuration File" in the phpinfo() page
and copy the path like the screenshot below

then open the php.ini in the editing mode using the code below, when you are in the folder of your php version, 

cd /opt/homebrew/etc/php/8.0

then 

sudo nano php.ini

when you get into the file search about upload_max_filesize you can search in the terminal using Ctrl W then you can update it to 6M or whatever you want, and also increase the post_max_size, max_file_uploads and to avoid the run out time you can increase max_execution_time, example of editing the upload_max_filesize attached below 

then don't forget to restart the php service using 

sudo service php8.0-fpm restart

That's all let me know if you have another questions

Jo Micheal Date : 2021-12-19

Thank you Joseph for this explanation, i followed your leads and everything works fine

Mohamed Atef Date : 2021-12-19

Best answers

51

Best answers

51

You can fix it as Joseph said by increasing the limit of upload files in the server, or you can limit it in the users using Validator class like the code below

 public function uploadImageAjax(Request $req){ $validator = Validator::make($req->all(), [ 'image' => 'required|image|mimes:jpeg,jpg,png,gif|max:2048', ]); if ($validator->fails()) { return response()->json($validator->errors(), 400); } if($req->image){ $image_name = basename( Storage::disk('public')->put('products/', $req->image)); $link = url('/').'/storage/products/'.$image_name; return $link; } }

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

[solved] All assets in laravel storage returns 404
Publish date: 2021-12-14 | Comments: 2
Laravel redirect to the last location after login
Publish date: 2022-02-21 | Comments: 1
How can I validate recaptcha in Livewire class ??
Publish date: 2022-02-23 | Comments: 2