Read xml file from HTTP post

Discussion in 'PHP' started by indukp, Jun 10, 2006.

  1. #1
    Hi All,
    I want to read an xml file which is sent through http post and store in my local disk in php.

    To be more clear, i have an url which send back an xml to the browser when run in IE. Now i want to save this xml in my local disk so that i have to extract the data from this xml and do the rest.

    Is there any guidelines for extracting data from post in php.

    Thanks
    Indu
     
    indukp, Jun 10, 2006 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,826
    Likes Received:
    4,541
    Best Answers:
    123
    Trophy Points:
    665
    #2
    As far as PHP is concerned the XML is just a great big text string when it comes from a form submit.

    Take the string and use fopen etc to create the file. You can then read it back like any other xml file.
     
    sarahk, Jun 10, 2006 IP
  3. indukp

    indukp Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks Sarah, but im facing still problem.
    I suceeded in getting the contents from post when its http://
    but when i use https:// the page is not loaded.
    when i use fsockopen an error comes like https:// is not opened. What can i do to solve this.

    my sample program is
    <?php

    //$handle = fopen("http://rss.news.yahoo.com/rss/highestrated/", "r");

    $handle = fopen("https://....", "r");
    $handle1 = fopen("test.xml","w");
    $contents = '';
    while (!feof($handle)) {
    $contents .= fread($handle, 8192);
    echo "https<br>";
    fwrite($handle1,$contents);
    }
    fclose($handle);
    fclose($handle1);
    ?>

    when i change the handle to the one i commented its working.
    Please help me
     
    indukp, Jun 10, 2006 IP
  4. ideas_man

    ideas_man Active Member

    Messages:
    212
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Any easier way would be to use file():

    $xml_string = file("https://www.yourdomain.com");

    Hope this helps :)
     
    ideas_man, Jun 10, 2006 IP
  5. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    file() returns the string as an array whereas file_get_contents() will return it as a string and should also be convenient with https connections. However, if you have issues with the secure connection you should use cURL.

    Bobby
     
    Chemo, Jun 10, 2006 IP
  6. ideas_man

    ideas_man Active Member

    Messages:
    212
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Quite right, took my eye off the ball there :eek: :)
     
    ideas_man, Jun 15, 2006 IP