简体   繁体   中英

How to delete old images from public folder on update using laravel

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? Your help will be appreciated.

尝试使用这个:

File::delete($file_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM