Search code examples
phpxmlftpsimplexml

Load file name with spaces from FTP


I'm trying to load a xml file from an external ftp server. Sadly the filename contains a space between two words.

Homepage-Filename Statistics-170210.xml

I'm able to load the file with simplexml_load_file, if there is an underscore a dash. For example:

Homepage-Filename_Statistics-170210.xml

simplexml_load_file('ftp://username:[email protected]/Homepage_Filename_Statistics-170210.xml');

But I'm not able to change the file name, so I have to load the file with spacing inside.

I have tried to replace the space with %20 or backslash / , but it isn't working either. For example:

Homepage_Filename%20Statistics-170210.xml

or

Homepage_Filename/ Statistics-170210.xml

Someone has an idea, how load something like this?

Thanks!


Solution

  • I can also reproduce this problem with the simplexml_load_file.

    Interestingly the file_get_contents works:

    $url = 'ftp://username:[email protected]/Homepage_Filename/ Statistics-170210.xml';
    simplexml_load_string(file_get_contents($url));