Interesting I have the same problem...its because the pah part of url have spaces.. so i use rawurlencode()for that part and yeah problem solved
my code:
$url1="http://localhost";// this is ok 
$url2="http://localhost/sample file name.txt";//this i have problem
$filename = "Write this down to keepass.txt";
$url2 = "http://localhost/" . rawurlencode($filename);//raw encode just the path part
$url3="http://localhost/a.txt";//and this is ok  also
$page = file_get_contents($url2);
var_dump($page);