PHP:具有空格的路径上的file_exists()和copy()

The system I'm operating on is CentOS 6. Suppose I have this filepath: /var/www/examplesite.com/uploads/Dog Photos/happy dog.jpg

To support spaces, I'm running a simple $filepath = str_replace(' ', '\\ ', $filepath) to escape the whitespace.

This results in a new filepath: /var/www/examplesite.com/uploads/Dog\ Photos/happy\ dog.jpg

However, file_exists($filepath) returns false.

This is odd because stat /var/www/examplesite.com/uploads/Dog\ Photos/happy\ dog.jpg returns the correct information on the file.

What am I doing wrong?

Make folder permission 777 to get all access of that folder. Also on file upload you can change the name of file just inserting underscore instead of space.