0

WHy am i getting this problem?

Intervention\Image\Exception\NotWritableException Can't write image data to path (C:\xampp\htdocs\laravel-ecommerce-master\storage\app/public/images/categories/bolu.jpg)

<?php

namespace App\Traits;

use Illuminate\Support\Str;
use Intervention\Image\Facades\Image;

trait ImageUploadTrait
{
    protected $path  = 'app/public/images/';

    public function uploadImage($name, $img, $folderName, $image_width = 400, $image_height = 400): string
    {
        $image_name = $this->imageName($name, $img);

        Image::make($img->getRealPath())->fit($image_width, $image_height, function ($constraint) {
            $constraint->aspectRatio();
        })->save(storage_path($this->path.$folderName.'/'.$image_name), 100);

        return $image_name;
    }

    public function uploadImages($name, $img, $i, $folderName, $image_width = null, $image_height = null): string
    {
        $image_name = $this->randomImageName($name, $img, $i);

        Image::make($img->getRealPath())
            ->fit($image_width, $image_height, function ($constraint) {
                $constraint->aspectRatio();
            })->save(storage_path($this->path.$folderName.'/'.$image_name), 100);

        return $image_name;
    }

    protected function imageName($imageName, $image): string
    {
        return Str::slug($imageName) . '.' . $image->getClientOriginalExtension();
    }

    protected function randomImageName($imageName, $image, $i): string
    {
        return Str::slug($imageName) . time() . '-' . $i . '.' . $image->getClientOriginalExtension();
    }
}

Please help me solve this problem, and thanks for the help

ADyson
  • 57,178
  • 14
  • 51
  • 63
SLOTH
  • 1
  • 1
    Does this answer your question? [Intervention\Image\Exception\NotWritableException Can't write image data to path](https://stackoverflow.com/questions/58891527/intervention-image-exception-notwritableexception-cant-write-image-data-to-path) – Nebojsa Nebojsa Jul 20 '23 at 11:17
  • Duplicate [stackoverflow link](https://stackoverflow.com/questions/58891527/intervention-image-exception-notwritableexception-cant-write-image-data-to-path) – Nebojsa Nebojsa Jul 20 '23 at 11:17
  • PHP likely doesn't have permission to write to the path. Or more accurately, the user under which the webserver runs when executing your application and PHP scripts doesn't have permission. So please correct your filesystem permissions accordingly – ADyson Jul 20 '23 at 11:19

0 Answers0