删除文件时出现问题:Laravel 5.4

Issue while deleting the file : Laravel 5.4

$path = public_path(). '/Images/';
$this->MakeDirectory($path);

$this->DeleteOldProfileImage($path. \Auth::guard("api")->user()->ProfileImage);

当我打印 url 时: 如下所示: C:\xampp\htdocs\My\Learning\admin/public/Images/ajax-loader.gif

如本地主机上的以下代码,文件不存在。

private function DeleteOldProfileImage($filePath) {
    if (\File::exists($filePath))
    {      
        \File::delete($filePath);
    }
}

当我 运行 服务器上的相同代码时,它可以工作。我假设这是由于斜线。你能推荐一下吗?

尝试 运行 您通过 realpath() 的路径,这应该可以清除混合斜杠和 return 完全限定的路径。

根据docs

echo realpath('/windows/system32');

会return

C:\WINDOWS\System32

所以试试运行

$path = public_path(). '/Images/';
$this->MakeDirectory(realpath($path));