0

Here is my Controller

public function store()
{ 
    $data = Request::all();

    $rules = [
                'password'   => 'required|confirmed|min:3',
                'avatar'     => 'required|image|mimes:jpeg,png,bmp',
                'email'      => 'required|email|unique:users',
                'first_name' => 'required',
                'last_name'  => 'required',
                'level'      => 'required'
            ];

    $validator = validator::make($data, $rules);

    if($validator->passes()){
        if(!file_exists(public_path("assets/uploads".date('/Y/m/d/').$data['avatar']->getClientOriginalName()))){
            $path = public_path("assets/uploads".date('/Y/m/d/').$data['avatar']->getClientOriginalName());
            Image::make($data['avatar']->getRealPath())->resize(200, 200)->save($path);
        }
    }
}

And Here is my error

Can't write image data to path (/var/www/html/rnd/public/assets/uploads/2015/10/16/tes.jpg)

There is no 2015 folder inside uploads folder, so it should create automatically if folder doesn't exists.

Please correct whats wrong with my code?

Any help appreciated.

mergenchik
  • 1,129
  • 16
  • 27
Dark Cyber
  • 2,181
  • 7
  • 44
  • 68

1 Answers1

0

Please make sure the folder you want to write to is exists with the correct owner www-data:www-data and correct permission, one more again keep in mind.

Image::make($data['avatar']->getRealPath())->resize(200, 200)->save($path);

The above code doesn't create folder automatically if folder doesn't exist as developer says here

https://github.com/Intervention/image/issues/56

Dark Cyber
  • 2,181
  • 7
  • 44
  • 68