[英]Download xml file from https using php
當我單擊https://www.omniva.ee/locations.xml時,我可以下載xml文件。
是否可以使用PHP獲取此文件的內容並將其保存到MySQL數據庫?
我嘗試了此示例,但沒有任何結果(未找到任何錯誤,但服務器上的php.ini文件的值為0):
PHP版本5.6.19指令本地值主值
allow_url_fopen 0 0 allow_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);
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.