Filenames with spaces
I am running PHP locally (no webserver involved at all). I am having trouble accessing a file with spaces in the path.

My bare bones case is

    $indexFile = "file:///Users/username/Documents/My Folder/test.txt"
    echo file_exists($indexFile);

or:

    $indexFile = "file:///Users/username/Documents/My‰20Folder/test.txt"
    echo file_exists($indexFile);

AFAICT this latter case is a well-formed file scheme URI. It's exactly what appears in the browser location field if I drag the file in there.

URI's without spaces don't have any problem. Unfortunately I am not at liberty to change "My Folder" to "MyFolder", and besides, I want to find a solution.

I tried using urlencode, rawurlencode, escapeshellarg, I've tried replacing %20 with a backslash-escaped space `"My\ Folder"` but none of this works. I've also hunted through google and stackoverflow, but while there are many suggstions, the question remains unanswered:

How to access an arbitrary file (on the local host) using a path which contains spaces?
Filenames with spaces
===

I am running PHP locally (no webserver involved at all). I am having trouble accessing a file with spaces in the path.

My bare bones case is

    $indexFile = "file:///Users/username/Documents/My Folder/test.txt"
    echo file_exists($indexFile);

or:

    $indexFile = "file:///Users/username/Documents/My‰20Folder/test.txt"
    echo file_exists($indexFile);

AFAICT this latter case is a well-formed file scheme URI. It's exactly what appears in the browser location field if I drag the file in there.

URI's without spaces don't have any problem. Unfortunately I am not at liberty to change "My Folder" to "MyFolder", and besides, I want to find a solution.

I tried using urlencode, rawurlencode, escapeshellarg, I've tried replacing %20 with a backslash-escaped space `"My\ Folder"` but none of this works. I've also hunted through google and stackoverflow, but while there are many suggstions, the question remains unanswered:

How to access an arbitrary file (on the local host) using a path which contains spaces?