skip to Main Content

So I have this code for uploading images in my laravel app:

 $imageName = rand(111, 99999) . '.' . $extension;
 $imagePath = 'images/category_images/' . $imageName;

 Image::make($image_tmp)->resize(533, 533)->save($imagePath);

It works perfectly on localhost, but after deploying the code online, I can’t read or write images from the admin panel of my app. It works on the user part though (The user part can read images).

I’ve set the permissions on the folders to 775 and on files to 644. So I really have no idea why this isn’t working. Please help

This is the error I get when I try to upload:

Intervention  Image  Exception  NotWritableException

Can’t write image data to path (images/category_images/74327.png)

2

Answers


  1. Try wrapping it with public_path($path)

    $imagePath = public_path('images/category_images/' . $imageName); 
    
    Login or Signup to reply.
  2. you don’t specify where you want to store your image as I can see you try to store it in the /image folder or it’s not recommended and I think you don’t have a permission to write there.
    So if you want to store in the public folder public/image:
    $imagePath ='images/category_images/'.$imageName;
    as mentioned in the first answer or if you want to store in the storage path add storage_path(‘path’) and if you do this do forget to link the storage path by executing the command

    php artisan storage:link

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search