Search code examples
laravellaravel-5.3laravel-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);

When i printed the url: It is like below: C:\xampp\htdocs\My\Learning\admin/public/Images/ajax-loader.gif

as below code on localhost, file does not exists.

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

When I run the same code on server, it works. Ia m assuming this is due to slashes. Can you please suggest?


Solution

  • Try running your path through realpath() which should clean up the mixed slashes and return a fully qualified path.

    According to the docs:

    echo realpath('/windows/system32');
    

    would return

    C:\WINDOWS\System32
    

    So try running

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