-1

I want to delete older images in public folder on update:

My Controller code:

try {
    $path = public_path('profile_images');
    @mkdir($path, '0777', true);

    $image = base64_decode($image);

    $imageName = str_random(10).'.'.'png';
    Storage::disk('profile-image')->put($imageName, $image);


    $path = asset('public/profile_images/' . $imageName);

    $this->userBasicInfo->where('user_id', $user_id)->update(['profile_pic' => $path]);

    return response(['status' => true, 'message' => 'Image Uploaded successfully', 'data' => ['profile_image' => $path]], 200);

} catch (\Exception $ex) {
    return response(['status' => false, 'message' => $ex->getMessage()], 500);
}

How can I achieve the delete functionality?

halfer
  • 19,824
  • 17
  • 99
  • 186
syed1234
  • 761
  • 5
  • 12
  • 30

1 Answers1

0

Try to use this:

File::delete($file_path)
jkdev
  • 11,360
  • 15
  • 54
  • 77
Giang D.MAI
  • 244
  • 1
  • 5