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

How can i pass data from blade template to vue component?
Publish date: 2022-02-11 | Comments: 1
Undefined Variable problem on Laravel 9.x
Publish date: 2022-03-06 | Comments: 3
Get user location (city - country) from his IP address
Publish date: 2022-03-02 | Comments: 2
[solved] Class "App\Exceptions\Client" not found
Publish date: 2022-02-09 | Comments: 2
How to get original attribute value in Laravel?
Publish date: 2022-02-23 | Comments: 3
Laravel API POST method returns 419
Publish date: 2022-08-03 | Comments: 1