unlink()不会从数据库中删除文件

时间:2017-09-23 04:17:46

标签: laravel

我遇到了unlink()的问题,我之前使用过并且工作正常,但在这个特殊的情况下它不是。将解释。

这是代码

public function kill($id){

$post = Post::withTrashed()->where('id', $id)->first();



unlink(public_path(). "/" . $post->featured);

$post->forceDelete();

Session::flash('success', 'Post has been permanently deleted');

return redirect()->back();
}

我收到此错误 PostsController.php第158行中的ErrorException: unlink(/ Applications / XAMPP / xamppfiles / htdocs / angie / public / http://angie.dev/uploads/posts/1506133455image_1.jpg):没有这样的文件或目录

所以基本上是添加" http://angie.dev/"在文件名之前。但是查看数据库文件名是正常的。我怎么摆脱它?

感谢

1 个答案:

答案 0 :(得分:0)

使用此

unlink(public_path(). str_replace("angie.dev/","/", $post->featured));
相关问题