XML PHP MYSQL- Writing to a xml file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jordan79
    New Member
    • Mar 2008
    • 20

    #1

    XML PHP MYSQL- Writing to a xml file

    I have code written to generate xml data in PHP from my MySQL database. I can display this in my browser using "echo" but wbat I really want is to write this xml data to a seperate xml file so that I can have flash use it.

    Here is my code:


    [PHP]<?php require_once('C onnections/PhotoABC.php'); ?>
    <?php
    if (!isset($_SESSI ON)) {
    session_start() ;
    }

    $sqluserid = "SELECT `user_id` FROM `user` WHERE `username` = '".$_SESSION['MM_Username']."'";
    $useridqueryres ult = mysql_query($sq luserid)
    or die (mysql_error()) ;
    if (mysql_num_rows ($useridqueryre sult) > 0) {
    $row=mysql_fetc h_assoc($userid queryresult);
    $userid=$row['user_id'];
    }

    $sqlimagename = "SELECT `image_name` FROM `gallery` WHERE `user_id` = '$userid'";
    $imagenamequery result = mysql_query($sq limagename)
    or die (mysql_error()) ;

    $xml_output = "<?xml version=\"1.0\" ?>\n";
    $xml_output .= "<images>\n ";

    for($x = 0 ; $x < mysql_num_rows( $imagenamequery result) ; $x++){
    $row = mysql_fetch_ass oc($imagenamequ eryresult);
    $xml_output .= "\t<image>\ n";
    xml_output .= "\t\t<image >" . $row['image_name'] . "</image>\n";
    $xml_output .= "\t</image>\n";
    }

    $xml_output .= "</images>";

    echo $xml_output;

    ?>[/PHP]

    I would like to write this xml data to a new xml file called "images" and to save it to this directory
    "C:\htdocs\Phot oABC\upload_tes t\Jordan"

    Any help would be great :)
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Have a look at this tutorial on creating files: http://w3schools.com/php/php_file.asp

    You could just create a file, then fwrite() the xml to it and save it as an xml file.
    :)

    Comment

    • Jordan79
      New Member
      • Mar 2008
      • 20

      #3
      Thanks
      I will have a look at doing it that way...

      I have tried it using "file_put_conte nts"
      But get this error:

      Warning: file_put_conten ts(C://htdocs//PhotoABC//upload_test//Jordan) [function.file-put-contents]: failed to open stream: Permission denied in C:\htdocs\Photo ABC\xml.php on line 43

      Could this have to do with permissions?
      I have uploaded images and created folders with no problem?

      Thanks for any help :)

      [PHP]$filename= 'C://htdocs//PhotoABC//upload_test//'.$_SESSION['MM_Username'];

      file_put_conten ts($filename ,$xml_output);[/PHP]

      Comment

      • Jordan79
        New Member
        • Mar 2008
        • 20

        #4
        I have this working now.
        Here is the code I used:
        [PHP]
        $filenamepath .= "images.xml ";

        $fp = fopen($filename path,'w');

        $write = fwrite($fp,$xml _output);

        echo $xml_output; [/PHP]
        Thanks for your help

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by Jordan79
          I have this working now.
          Here is the code I used:
          [PHP]
          $filenamepath .= "images.xml ";

          $fp = fopen($filename path,'w');

          $write = fwrite($fp,$xml _output);

          echo $xml_output; [/PHP]
          Thanks for your help
          Welcome mate :)
          see you around

          Comment

          Working...