Laravel 开发时删除文件 windows

Laravel delete file while developing windows

在我的本地开发环境中(xampp、windows)我有文件

D:\Documents\repos\somerepo\public\img\bathroom\small\someimage.jpg

我尝试删除它:

Storage::delete(public_path('img/bathroom/8/small/someimage.jpg'));

但是在 运行 代码后文件仍然存在。 当我打印 public_path('img/bathroom/8/small/someimage.jpg') 的路径并将其复制到文件浏览器中时,它可以很好地打开文件。 如何让 laravel 删除文件?

当我运行:

    if(File::exists($path)){
        return $path." Does not exist";
    }

路径是 public_path('img/bathroom/8/small/someimage.jpg') 它告诉我它不存在。

假设您使用的是默认文件系统配置,the public disk stores files in storage/app/public. The local disk 使用 storage/app。总之,两个本地盘都管理storage/.

下的文件

The public_path() helper returns public 目录的完全限定路径。所以:

public_path('img/bathroom/8/small/someimage.jpg')

会生成这样的路径:

/your/project/public/img/bathroom/8/small/someimage.jpg

请注意,这 不是 storage/ 下,其中两个 Storage 本地磁盘都在运行。在其管理的文件系统的根目录之外传递 Storage 完全限定路径将不起作用。

要在 外部 配置 Storage 的磁盘的根目录下工作,您必须使用标准 PHP 函数,例如 unlink(),等等。或者,将要使用 Storage 维护的文件移动到它配置的磁盘之一,add the symlink 以使它们可见,并更新对这些文件的引用观看次数等