$path = public_path(). '/Images/';
$this->MakeDirectory($path);
$this->DeleteOldProfileImage($path. \Auth::guard("api")->user()->ProfileImage);
当我打印网址时:如下所示:C:\ xampp \ htdocs \ My \ Learning \ admin / public / Images / ajax-loader.gif
如下所示localhost上的代码,文件不存在。
private function DeleteOldProfileImage($filePath) {
if (\File::exists($filePath))
{
\File::delete($filePath);
}
}
当我在服务器上运行相同的代码时,它可以工作。我认为这是由于斜线。你能建议吗?
答案 0 :(得分:1)
尝试通过realpath()
运行路径,该路径应清理混合斜杠并返回完全限定的路径。
根据docs:
echo realpath('/windows/system32');
将返回
C:\WINDOWS\System32
所以尝试运行
$path = public_path(). '/Images/';
$this->MakeDirectory(realpath($path));