Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.