sanjayacloud's avatar

Permission denied when delete image from file path

Hi Friends,

I am trying to delete a uploaded image file from path in laravel 5.4. But when I trying to delete it I have got following error.

"unlink(E:\xampp\htdocs\project-path\public/images/pages/): Permission denied"

My controller like this

  public function destroy(Request $request, $id)
    {
        $id = decode($id);
        $img =  $request->imgValue;
        $Path = public_path().'/images/pages/'.$img;
       // fclose($Path);
        if(file_exists($Path)){
            unlink($Path);
        }
        if($request->ajax()){

            if(\App\Image::destroy($id)){
                return response()->json(array(
                    'success' => true
                ));
            }
        }else{
            return redirect()->action('UsersController@index');
        }

    }

Any one know solution for this error what I got above?

0 likes
4 replies
thaMink's avatar

Try using Storage::delete()

$path = '/images/pages/'. $img;
Storage::delete($path);
Nakash's avatar

Hi sanjayacloud,

Have you checked that the rights on the pages folder and on its content were 777 or 755?

Please or to participate in this conversation.