Jump to content

HELP with PHP script to save XML file


phpnewbie09

Recommended Posts

I have this script:

<?php
$initFile = "init.xml";
$progressFile = "progress.xml";

$command = "load";
if(isset($_GET["command"]){
$command = $_GET["command"];
}

switch($_GET["command"]){
case "save":
	if (isset($_POST['xml'])) {
		if(write($_POST['xml'])){
			output("", "Synchronisation succeeded.");
		} else {
			output("", "Could not write file.");
		}
	} else {
		output("", "Could not find XML for output.");
	}
break;
case "load":
	if(!file_exists($progressFile))}
		if (!copy($initFile, $progressFile)) {
			output("", "Could not find XML for output.");
		}
	}
	output("Content-Type: text/xml", read($progressFile);
break;
}

function output($headers="", $output){
if($headers=""){
	$headers = "Content-Type: text/plain";
}
header ($headers);
echo ($output);
}

function write($xml, $file){
if($f = fopen($file, "w")){
	fwrite($f, $xml);
	fclose($f);
	return true;
} else {
	return false;
}
}

function read($file){
return file_get_contents($file);
}

?>

 

However this script could only update the $progressFile and if I save the file it will only do them locally, I want to save the XML file into the server. Anyone can help me?

 

Or does anyone have any script to save file to the server from a remote machine?

 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/163316-help-with-php-script-to-save-xml-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.