Mercurial > hg > webaudioevaluationtool
annotate save.php @ 1221:310b4640b93d
Better solve for #1629
author | Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk> |
---|---|
date | Tue, 23 Feb 2016 16:59:59 +0000 |
parents | 585e06d319d2 |
children | 124e6c702845 |
rev | line source |
---|---|
BrechtDeMan@715 | 1 <?php |
n@1221 | 2 try{ |
n@1221 | 3 date_default_timezone_get(); |
n@1221 | 4 } |
n@1221 | 5 catch(Exception $e){ |
n@1221 | 6 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini |
n@1221 | 7 } |
BrechtDeMan@746 | 8 header('Access-Control-Allow-Origin: *'); |
nicholas@748 | 9 header("Content-type: text/xml"); |
giuliomoro@1088 | 10 error_reporting(0); |
BrechtDeMan@715 | 11 $postText = file_get_contents('php://input'); |
nicholas@829 | 12 $sha1_hash = sha1($postText); |
BrechtDeMan@715 | 13 $datetime = date('ymdHis'); |
nicholas@829 | 14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
BrechtDeMan@715 | 15 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
nicholas@748 | 16 if ($fileHandle == FALSE) |
nicholas@748 | 17 { |
nicholas@748 | 18 // Filehandle failed |
nicholas@748 | 19 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@748 | 20 echo $xml; |
nicholas@748 | 21 return; |
nicholas@748 | 22 } |
nicholas@748 | 23 $wbytes = fwrite($fileHandle, $postText); |
giuliomoro@1215 | 24 if ($wbytes === FALSE) |
nicholas@748 | 25 { |
nicholas@748 | 26 // FileWrite failed |
nicholas@748 | 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nicholas@748 | 28 echo $xml; |
nicholas@748 | 29 return; |
nicholas@748 | 30 } |
BrechtDeMan@715 | 31 fclose($fileHandle); |
nicholas@748 | 32 |
nicholas@748 | 33 // Return JSON confirmation data |
nicholas@748 | 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nicholas@748 | 35 echo $xml; |
giuliomoro@1214 | 36 ?> |