简体   繁体   中英

Download xml file from https using php

I can download xml file when I click on https://www.omniva.ee/locations.xml .

Is it possible to get the contents of this file using PHP and save these to a MySQL database?

I tried this example but without any result (no arrors found but php.ini file on server has value 0):

PHP Version 5.6.19 Directive Local value Master value
allow_url_fopen 0 0 allow_url_include no value no value

$xml = file_get_contents("https://www.omniva.ee/locations.xml");

If allow_url_fopen is disabled you have no possibility to get the file content of the external file with file_get_contents() . Instead of using file_get_contents() you can use curl to get the content of the file:

<?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);
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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