SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    writing to an xml file using php

    Hi,

    Ive built a flash mp3 player that uses an xml file to get the mp3 files in to the flash. What i want to do is build a backend that allows users to upload new mp3s. What i need to happen is for the xml file to be updated everytime a new file is uploaded.

    I have no problems creating the script for the upload and creating the corresponding xml. I can simply use while loops to create the xml structure/ nodes and insert the mp3 whilst in one of these loops. Problem is i have now clue how to write to an xml file.

    Is there any way i can open the xml file up and write the xml that my php script has created to it? I can get the script to a stage where it has created the required xml and is able t echo it out.

    Ive googled for this but cant find a satisfactory answer.

    Any ideas?

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry some more googling gave me what i needed!

    http://www.ibm.com/developerworks/library/os-xmldomphp/

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right,

    Ive got it worked out and i can open and write to an xml file no problem. What i want to do is only have five records in the xml file. Currently what im doing is on success of an uploaded file im querying the database for the five most recent uploaded files and then iterting through these and turning them in to xml and putting them in the xml file and then writing it.

    Problem is the previous five xml files are still there. What i want to do is everytime an upload is made and is successfully put in the db i want to do a query, get the last 5 records, open the xml file, somehow delete the previous contents and then re-write the file with the results of the query just made....make sense....?!

    Is there any way to do that?

    Thanks

  4. #4
    SitePoint Wizard
    Join Date
    Oct 2005
    Location
    London
    Posts
    1,678
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    urrghh! I keep answering my own questions...sorry!

    I think im going to use unlink to delete the old file and then build a new one. If anyone can see any problems with this approach please let me know


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •