annotate save.php @ 555:4cc5bc731a3d Dev_main

Added error check for empty file in save.php
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 23 Feb 2016 14:18:25 +0000
parents a95d323a911e
children 80796ff2ae66
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');
giuliomoro@555 10 if (sizeof($postText) <= 1)
giuliomoro@555 11 {
giuliomoro@555 12 // Filehandle failed
giuliomoro@555 13 $xml = '<response state="error"><message>Input file empty</message></response>';
giuliomoro@555 14 echo $xml;
giuliomoro@555 15 return;
giuliomoro@555 16 }
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);
nicholas@345 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 ?>