繁体   English   中英

使用php从https下载xml文件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM