如何在更新 lumen/laravel 中的数据之前从项目的 public 文件夹中删除照片?
How to delete photo from project's public folder before updating data in lumen/laravel?
我想在更新另一张照片之前从我的项目 public 文件夹中删除照片。我的代码看起来像-
if(File::exist( $employee->avatar)){
//$employee->avatar looks /uploads/avatars/1646546082.jpg and it exist in folder
File::delete($employee->avatar);
}
这对我来说不起作用。如果我评论这些代码,则另一张照片会更新而不会完美删除。我该如何解决这个问题!
try php unlink function
$path = public_path()."/pictures/".$from_database->image_name;
unlink($path);
This is the code which i use in update profile picture you can do this exactly like this
$data=Auth::user();
if($request->hasFile('image')){
$image = $request->file('image');
$filename = 'merchant_'.time().'.'.$image->extension();
$location = 'asset/profile/' . $filename;
Image::make($image)->save($location);
$path = './asset/profile/';
File::delete($path.$data->image);
$in['image'] = $filename;
$data->fill($in)->save();
}
我想在更新另一张照片之前从我的项目 public 文件夹中删除照片。我的代码看起来像-
if(File::exist( $employee->avatar)){
//$employee->avatar looks /uploads/avatars/1646546082.jpg and it exist in folder
File::delete($employee->avatar);
}
这对我来说不起作用。如果我评论这些代码,则另一张照片会更新而不会完美删除。我该如何解决这个问题!
try php unlink function
$path = public_path()."/pictures/".$from_database->image_name;
unlink($path);
This is the code which i use in update profile picture you can do this exactly like this
$data=Auth::user();
if($request->hasFile('image')){
$image = $request->file('image');
$filename = 'merchant_'.time().'.'.$image->extension();
$location = 'asset/profile/' . $filename;
Image::make($image)->save($location);
$path = './asset/profile/';
File::delete($path.$data->image);
$in['image'] = $filename;
$data->fill($in)->save();
}