Using PHP and DOMDocument

Discussion in 'PHP' started by NoamBarz, Feb 26, 2008.

  1. #1
    I would like to read excel files.
    I thought the easiest way to do so would be to save the excel file as an XML speardsheet and load the data using PHP and DOMDocument.

    I first tried using the following code to read the data of an uploaded XML spreadsheet:

    if ( $_FILES['pricefile']['tmp_name'] ){

    $dom = new DomDocument('1.0');
    $dom->load($_FILES['pricefile']['tmp_name']);
    echo $dom->saveXML();

    }

    Obviously, I have a form which submits to this page and which contains the HTML form element <input name="pricefile" type="file" />

    The result should be that the page display the XML content of the uploaded file. However, in practice, all I get is the first line in the XML document:
    <?xml version="1.0"?>

    and nothing after that.

    Can anyone think of a reason why this is happening?
     
    NoamBarz, Feb 26, 2008 IP
  2. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $dom->load(file_get_contents($_FILES['pricefile']['tmp_name'])); by any chance? Seems like you'd only be loading the name '124afa3r.tmp' instead of the xml data.
     
    decepti0n, Feb 26, 2008 IP
  3. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Thanks deceptiOn.
    What you said makes complete sense, but doesn't work.
    I still get the same result.
     
    NoamBarz, Feb 26, 2008 IP
  4. NoamBarz

    NoamBarz Active Member

    Messages:
    242
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #4
    Ok, I got it.
    The problem was, to whom it may concern, that I was trying to load the data from it's temporary upload location. In order to have things work properly, the file must first be uploaded and copied to a chosen location. You can then load the file content and move on.
     
    NoamBarz, Feb 26, 2008 IP