PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
What is the mechanism that you want to use to send the XML to this remote server? Would it be via HTTP POST? Or would you be FTPing an XML file to somewhere? Please give more details.
to be honest we are still looking what the best way is. But it could be either HTTP or through FTP since we also need to pull and push data automatically to the server.
If I wanted to go with the HTTP, what sort of PHP script should be use?
1. Line 12 should be switching on $command, not $_GET['command'].
2. As defined on line 42, write() requires two parameters. Yet on line 15, write() is called with only one argument. This call to write() will always fail and the file will not be saved to the server.
3. Line 35 assigns an empty string to $headers rather than comparing $headers to an empty string. The condition on line 35 will always be true.
Edit: This post was recovered from search engine cache.
Last edited by McInfo on Wed Jun 16, 2010 11:37 am, edited 1 time in total.
Look at the definition for write() on line 42. The second argument for write() should be a string containing the path to a file where you want to save the XML. It is the same as the $filename parameter of the fopen() function.
<?php
$initFile = "init.xml";
$progressFile = "progress.xml";
if (isset($_POST['xml'])) { // SAVE
if(write($_POST['xml'], $progressFile)){
output("", "Synchronisation succeeded.");
} else {
output("", "Could not synchronise - write error.");
}
} else { // LOAD
if(!file_exists($progressFile)){
if (!copy($initFile, $progressFile)) {
output("", "Could not find XML for output.");
}
chmod($progressFile, 0755);
}
output("Content-Type: text/xml", read($progressFile));
}
function output($headers="", $output){
if($headers == ""){
$headers = "Content-Type: text/plain";
}
header ($headers);
echo ($output);
}
function write($xml, $file){
$f = fopen($file, "w") or die('Could not open file for writing.');
fwrite($f, html_entity_decode($xml));
fclose($f);
return true;
}
function read($file){
return file_get_contents($file);
}
?>
This code does save the file which in this case "progress.xml" file to the server, however it also need to generate a new file after a "game" ends and at the moment it is just overwriting the current "progress.xml"... Do you have any script that could do this?
And is there an HTTP path script where it could also save the "progress.xml" file to the webserver too?
Thanks
Last edited by Benjamin on Tue Jun 23, 2009 11:40 pm, edited 1 time in total.
Reason:Changed code type from text to php.
I'm not sure exactly what rules you want your script to follow, but if you just want to save the XML to a uniquely named file each time the script runs, you can use time() to generate a file name like "progress_1245810823.xml".