如果我删除任何显示该页面的内容,我将无法删除文章或图片if(!function_exists('image_delete')){ function image_delete($dir){ unlink(public_path().'/'.$dir); }} /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy(Article $article) { image_delete($article->image); // its helper function $article->delete(); return back()->with('success','تم حذف المقال !!'); }这是我的问题
2 回答
幕布斯6054654
TA贡献1876条经验 获得超7个赞
在删除任何文件或文件夹之前,请检查文件或文件夹是否存在。像这样更改您的助手代码。这里 file_exist 函数检查你的目录或文件是否存在。
if(!function_exists('image_delete')){
function image_delete($dir){
if(file_exists($dir))
unlink(public_path().'/'.$dir);
}
}
鸿蒙传说
TA贡献1865条经验 获得超7个赞
例如,您的文章图像存储在 public/article_images 目录中,然后按照以下代码进行编码。
在帮手中:
if(!function_exists('image_delete')){
function image_delete($filename){
$file = public_path().'/article_images/'.$filename;
if(file_exists($file)){
unlink($file);
}
}
}
- 2 回答
- 0 关注
- 176 浏览
添加回答
举报
0/150
提交
取消