user3610219
user3610219

Reputation: 75

Saving XML File from URL on my Server

I am able to put the following url in any browser and the xml appears after a few seconds... ftp://USER:[email protected]/exports/xml/products.xml

I tried the following code in a php file so I can run a cron daily at midnight and for it to save the xml file on my server. There is a xml file being saved in my data directory but it is blank. Any ideas?

<?php 
$content =     file_get_contents('ftp://USER:[email protected]/exports/xml/products.xml');
file_put_contents('./data/products.xml', $xml);
?>

Upvotes: 2

Views: 2904

Answers (2)

Ray Hunter
Ray Hunter

Reputation: 15557

Try this:

<?php 
$xml = file_get_contents('ftp://USER:[email protected]/exports/xml/products.xml');
file_put_contents('./data/products.xml', $xml);
?>

Your $content is not used in the file_put_contents method call so you are not writing anything to the file. I changed the code so that the data gets written to the file.

Upvotes: 1

Ahmad
Ahmad

Reputation: 1039

Nothing wrong with your code since file_get_contents almost supports all the protocols, But you may need to change $xml to $content because as I see $xml variable does not exists in your code.

Upvotes: 0

Related Questions