annotate save.php @ 534:a95d323a911e giulio-working

The version I use and works, addresses issues #1622, #1616, partially #1620
author Giulio Moro <giuliomoro@yahoo.it>
date Mon, 22 Feb 2016 04:17:19 +0000
parents 9823ee8c823e
children 4cc5bc731a3d
rev   line source
n@292 1 <?php
b@343 2 header('Access-Control-Allow-Origin: *');
nicholas@345 3 header("Content-type: text/xml");
giuliomoro@534 4 error_reporting(0);
n@292 5 $postText = file_get_contents('php://input');
nicholas@357 6 $sha1_hash = sha1($postText);
n@292 7 $datetime = date('ymdHis');
nicholas@357 8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
n@292 9 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@345 10 if ($fileHandle == FALSE)
nicholas@345 11 {
nicholas@345 12 // Filehandle failed
nicholas@345 13 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@345 14 echo $xml;
nicholas@345 15 return;
nicholas@345 16 }
nicholas@345 17 $wbytes = fwrite($fileHandle, $postText);
nicholas@345 18 if ($wbytes == FALSE)
nicholas@345 19 {
nicholas@345 20 // FileWrite failed
nicholas@345 21 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@345 22 echo $xml;
nicholas@345 23 return;
nicholas@345 24 }
n@292 25 fclose($fileHandle);
nicholas@345 26
nicholas@345 27 // Return JSON confirmation data
nicholas@345 28 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@345 29 echo $xml;
n@292 30 ?>