Laravel storage exists() returns false for file names with spaces

1.6k Views Asked by At

I'm trying to check if file exists using storage exists() function.

This function returns true if file name doesn't have spaces but false otherwise.

I'm trying to use Storage facades code as follows

if (Storage::disk("local")->exists($model->path)) { // path of the file 
    Storage::move(); // logic to move files
}

Storage folders has all permissions

I have lot of files with spaces in my storage subfolder F1. I want to move those file to another subfolder F2 inside storage itself. It would be tedious to rename each and every file for exists() to work.


Update

Php inbuilt file_exists() works for same path i.e it returns true if file is found and even if it has spaces in it's name.

Code for file_exists()


file_exists(storage_path() . '/app/F1/Demo One.pdf');

I have used tinker for debugging.

Why storage facades exists() returns false?

1

There are 1 best solutions below

6
ColinMD On

storage_path() and the local Storage disk have different base directories

storage_path() base directory is 'storage'

Storage::disk('local') base directory is 'storage/app'