大佬教程收集整理的这篇文章主要介绍了如果在laravel中删除了表数据行,如何删除文件?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
laravel 表数据行被删除如何删除文件?
代码:
public function destroy($ID)
{
$customer = customer::find($ID);
$exist_image=$customer->prooffile;
if (isset($exist_imagE) && file_exists($exist_imagE)) {
unlink($exist_imagE);
}
$customer->delete();
return $this->index();
}
我认为 file_exists()
在这里没有更好的方法来删除公共文件夹中的文件。
首先,您应该通过 realpath 运行 filepath,其次检查返回的路径是否为 writable,如果是,则为 unlink。
,如果您的 $exist_image
只返回 image name
那么
$customer = customer::find($id);
if(! $customer){
abort(403);
}
$exist_image=$customer->prooffile;
if(File::exists(public_path('userfiles/proof/'.$exist_imagE))) {
File::delete(public_path('userfiles/proof/'.$exist_imagE));
$customer->prooffile=null;
$customer->save();
}
导入右立面
use Illuminate\Support\Facades\File;
以上是大佬教程为你收集整理的如果在laravel中删除了表数据行,如何删除文件?全部内容,希望文章能够帮你解决如果在laravel中删除了表数据行,如何删除文件?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。