我可以在点击时下载xml文件https://www.omniva.ee/locations.xml.
是否可以使用PHP获取该文件的内容并将其保存到MySQL数据库中?
我尝试了这个例子,但没有任何结果(没有找到arror,但服务器上的php.ini文件的值为0):
PHP版本5.6.9指令本地值主值
allow_url_fopen 0 0allow_url_include无值无值
$xml = file_get_contents("https://www.omniva.ee/locations.xml");
如果禁用了allow_url_fopen
,则无法使用file_get_contents()
获取外部文件的文件内容。不使用file_get_contents()
,您可以使用curl
来获取文件的内容:
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://www.omniva.ee/locations.xml');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
//check if the curl_exec was successful.
if (curl_errno($curl) === 0) {
//success - file could be downloaded.
//write the content of $data in database here...
} else {
//error - file could not be downloaded.
}
//close the curl session.
curl_close($curl);
?>