Mercurial > hg > webaudioevaluationtool
annotate save.php @ 587:0d6d7618f6da Dev_main
WIP. Adding intermediate save options. Will require mass editing of save engine as it stands, so still WIP (note: this version will not work on python server).
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Wed, 09 Mar 2016 11:12:06 +0000 |
parents | 6833d8c2b52e |
children | 055f9763fada 328f24798462 |
rev | line source |
---|---|
n@292 | 1 <?php |
giuliomoro@583 | 2 error_reporting(0); |
n@563 | 3 try{ |
n@563 | 4 date_default_timezone_get(); |
n@563 | 5 } |
n@563 | 6 catch(Exception $e){ |
n@563 | 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini |
n@563 | 8 } |
b@343 | 9 header('Access-Control-Allow-Origin: *'); |
nicholas@345 | 10 header("Content-type: text/xml"); |
n@292 | 11 $postText = file_get_contents('php://input'); |
nicholas@357 | 12 $sha1_hash = sha1($postText); |
n@292 | 13 $datetime = date('ymdHis'); |
nicholas@357 | 14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
n@292 | 15 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
nicholas@345 | 16 if ($fileHandle == FALSE) |
nicholas@345 | 17 { |
nicholas@345 | 18 // Filehandle failed |
nicholas@345 | 19 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@345 | 20 echo $xml; |
nicholas@345 | 21 return; |
nicholas@345 | 22 } |
nicholas@345 | 23 $wbytes = fwrite($fileHandle, $postText); |
giuliomoro@556 | 24 if ($wbytes === FALSE) |
nicholas@345 | 25 { |
nicholas@345 | 26 // FileWrite failed |
nicholas@345 | 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nicholas@345 | 28 echo $xml; |
nicholas@345 | 29 return; |
nicholas@345 | 30 } |
n@292 | 31 fclose($fileHandle); |
nicholas@345 | 32 |
nicholas@345 | 33 // Return JSON confirmation data |
nicholas@345 | 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nicholas@345 | 35 echo $xml; |
giuliomoro@555 | 36 ?> |