Jo Micheal
19 Dec 2021
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?
Joseph Morgan
19 Dec 2021
Best Answer
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
19 Dec 2021
Thank you Joseph for this explanation, i followed your leads and everything works fine
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;
}
}
© 2024 Copyrights reserved for web-brackets.com