I have a php file which connect and grab data from a mysql database.
If I call this PHP page it displays the content of the table in a xml format.. so far everything works fine.
I would like this php page to also create/overwrite an xml file and save it in a directory on the server.
I know I need to use something like that
Code: Select all
<?
$file= fopen("myFile.xml", "w");
fwrite($file, not too sure what to put here);
fclose($file);
?>
Here is the page
Code: Select all
<?php
$hostname_conn = "localhost";
$database_conn = "image_gallery";
$username_conn = "root";
$password_conn = "";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
?>
<?php
// Query the database and get all the records from the Images table
mysql_select_db($database_conn, $conn);
$query_rsImages = "SELECT path,thumbpath,width,height,thumbwidth,thumbheight FROM images";
$rsImages = mysql_query($query_rsImages, $conn) or die(mysql_error());
$row_rsImages = mysql_fetch_assoc($rsImages);
$totalRows_rsImages = mysql_num_rows($rsImages);
// Send the headers
header('Content-type: text/xml');
header('Pragma: public');
header('Cache-control: private');
header('Expires: -1');
?>
<gallery
base = ""
background = "#FFFFFF"
banner = "#F0F0F0"
text = "#000000"
link = "#0000FF"
alink = "#FF0000"
vlink = "#800080"
date = "4/11/2006">
<sitename>China Gallery</sitename>
<photographer></photographer>
<contactinfo></contactinfo>
<email></email>
<security><![CDATA[]]> </security>
<banner font = "Arial" fontsize = "3" color = "#F0F0F0"> </banner>
<thumbnail base ="thumbnails/" font = "Arial" fontsize = "4" color = "#F0F0F0" border = "0" rows = "3" col = "5"> </thumbnail>
<large base ="images/" font = "Arial" fontsize = "3" color = "#F0F0F0" border = "0"> </large>
<photos id = "images">
<?php if ($totalRows_rsImages > 0) { // Show if recordset not empty ?>
<?php do { ?>
<photo
path="<?php echo $row_rsImages['path']; ?>"
width = "<?php echo $row_rsImages['width']; ?>"
height = "<?php echo $row_rsImages['height']; ?>"
thumbpath="<?php echo $row_rsImages['thumbpath']; ?>"
thumbwidth = "<?php echo $row_rsImages['thumbwidth']; ?>"
thumbheight = "<?php echo $row_rsImages['thumbheight']; ?>"
>
</photo>
<?php } while ($row_rsImages = mysql_fetch_assoc($rsImages)); ?>
<?php } // Show if recordset not empty ?>
</photos>
</gallery>
<?php
mysql_free_result($rsImages);
?>
Christophe