annotate save.php @ 607:328f24798462 multiple-tests-concatenation

working, hacked together.
author Giulio Moro <giuliomoro@yahoo.it>
date Fri, 11 Mar 2016 16:49:47 +0000
parents 6833d8c2b52e
children 0256f3748b27
rev   line source
n@292 1 <?php
giuliomoro@583 2 error_reporting(0);
giuliomoro@607 3 try{
giuliomoro@607 4 date_default_timezone_get();
giuliomoro@607 5 }
giuliomoro@607 6 catch(Exception $e){
giuliomoro@607 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini
giuliomoro@607 8 }
giuliomoro@607 9 $saveFilenamePrefix = isset($_GET['saveFilenamePrefix']) ? $_GET['saveFilenamePrefix'].'-' : '';
b@343 10 header('Access-Control-Allow-Origin: *');
nicholas@345 11 header("Content-type: text/xml");
n@292 12 $postText = file_get_contents('php://input');
nicholas@357 13 $sha1_hash = sha1($postText);
n@292 14 $datetime = date('ymdHis');
giuliomoro@607 15 $xmlfile = $saveFilenamePrefix."save".$datetime."-".$sha1_hash.".xml";
n@292 16 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@345 17 if ($fileHandle == FALSE)
nicholas@345 18 {
nicholas@345 19 // Filehandle failed
nicholas@345 20 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@345 21 echo $xml;
nicholas@345 22 return;
nicholas@345 23 }
nicholas@345 24 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@556 25 if ($wbytes === FALSE)
nicholas@345 26 {
nicholas@345 27 // FileWrite failed
nicholas@345 28 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@345 29 echo $xml;
nicholas@345 30 return;
nicholas@345 31 }
n@292 32 fclose($fileHandle);
nicholas@345 33
nicholas@345 34 // Return JSON confirmation data
nicholas@345 35 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@345 36 echo $xml;
giuliomoro@555 37 ?>