我想在更新时删除公用文件夹中的旧图像:
我的控制器代码:
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);
}
如何实现删除功能? 您的帮助将不胜感激。
答案 0 :(得分:1)
尝试使用
File::delete($file_path)