Home > Software engineering >  Move images into a folder in the public folder in Laravel but fails
Move images into a folder in the public folder in Laravel but fails

Time:09-23

I have three folders (userImages, productImages and clientImages) inside the images folder with the public folder in a Laravel(9.5.1) project. I am trying to upload images and move same into the productImages folder but it is not working. However, if I try with the userImages folder, it works and works only with that folder. I would be glad for any assistance from you. Thank you for your assistance in advance. This is code:

if($request->hasFile('product_image')){
    $image          = $request->file('product_image');
    $newImageName   = uniqid().'-'.Str::slug($request->product).'.'.$image->getClientOriginalExtension();
    $location       = public_path('/images/productImages');
    $image->move($location, $newImageName);
}else {
    $newImageName   = 'default_image.png';
}

The error message I get from the above line of code is:

The stream or file "/Applications/XAMPP/xamppfiles/htdocs/pos/storage/logs/laravel.log" could not be opened in append mode: Failed to open stream: Permission denied The exception occurred while attempting to log: The stream or file

CodePudding user response:

Please make 777 for storage folder permissions. Laravel tries to log the error to the log file. But storage folder permissions don't let it. Then you will see what is wrong with your code in the log file.

sudo chmod -R 777 storage

CodePudding user response:

You need to be specific with the directory you want to allow the permission. Like below for your case.

sudo chmod -R 777 /Applications/XAMPP/xamppfiles/htdocs/pos/public/images/productImages
  • Related