annotate save.php @ 1215:5df87aa95395

Actually the previous commit was broken. This contains a working and more elegant way of checking for the input file length. If the input file is empty, no error is triggered.
author Giulio Moro <giuliomoro@yahoo.it>
date Tue, 23 Feb 2016 14:39:06 +0000
parents dc4300033afc
children 585e06d319d2
rev   line source
BrechtDeMan@715 1 <?php
BrechtDeMan@746 2 header('Access-Control-Allow-Origin: *');
nicholas@748 3 header("Content-type: text/xml");
giuliomoro@1088 4 error_reporting(0);
BrechtDeMan@715 5 $postText = file_get_contents('php://input');
nicholas@829 6 $sha1_hash = sha1($postText);
BrechtDeMan@715 7 $datetime = date('ymdHis');
nicholas@829 8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
BrechtDeMan@715 9 $fileHandle = fopen("saves/".$xmlfile, 'w');
nicholas@748 10 if ($fileHandle == FALSE)
nicholas@748 11 {
nicholas@748 12 // Filehandle failed
nicholas@748 13 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@748 14 echo $xml;
nicholas@748 15 return;
nicholas@748 16 }
nicholas@748 17 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@1215 18 if ($wbytes === FALSE)
nicholas@748 19 {
nicholas@748 20 // FileWrite failed
nicholas@748 21 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@748 22 echo $xml;
nicholas@748 23 return;
nicholas@748 24 }
BrechtDeMan@715 25 fclose($fileHandle);
nicholas@748 26
nicholas@748 27 // Return JSON confirmation data
nicholas@748 28 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@748 29 echo $xml;
giuliomoro@1214 30 ?>