I am trying to run a simple script which grabs an xml file from a website and saves it
in to a file, below is the function
/* update exchange rates */
public function getLatestExchangeRates(){
$xml = file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml");
file_put_contents("xml/exchange_rates.xml", $xml);
}
echo "Update Exchange Rates <br>\n";
$scraper->getLatestExchangeRates();
running this script in chrome works but when running it in cmd prompt using the following statement
C:\xampp\php\php.exe -f C:\xampp\htdocs\sites\bk\update_exchange_rates.php
gives me the following error in the console..
warning: file_put_contents(xml/exchange_rates.xml: failed to open stream: no such file or directory in C:....
How do I fix this problem?
The simplest fix is to use the
global contant to build the path to use.
will give you the directory of where the current script is running, which will solve running through apache and command line.