Mercurial > hg > webaudioevaluationtool
annotate save.php @ 1238:8c56eda17acd
Error levels should be set before messing around with timezone, as that may trigger warnings on some systems
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Sun, 06 Mar 2016 20:55:00 +0000 |
parents | 124e6c702845 |
children | 987ccc04250b |
rev | line source |
---|---|
BrechtDeMan@715 | 1 <?php |
giuliomoro@1238 | 2 error_reporting(0); |
n@1221 | 3 try{ |
n@1221 | 4 date_default_timezone_get(); |
n@1221 | 5 } |
n@1221 | 6 catch(Exception $e){ |
n@1221 | 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini |
n@1221 | 8 } |
BrechtDeMan@746 | 9 header('Access-Control-Allow-Origin: *'); |
nicholas@748 | 10 header("Content-type: text/xml"); |
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 ?> |