Mercurial > hg > webaudioevaluationtool
annotate save.php @ 1879:059cac752536
Error levels should be set before messing around with timezone, as that may trigger warnings on some systems
author | Giulio Moro <giuliomoro@users.noreply.github.com> |
---|---|
date | Sun, 06 Mar 2016 20:55:00 +0000 |
parents | 40f256900cb5 |
children | 987ccc04250b |
rev | line source |
---|---|
b@1478 | 1 <?php |
giuliomoro@1879 | 2 error_reporting(0); |
nickjillings@1862 | 3 try{ |
nickjillings@1862 | 4 date_default_timezone_get(); |
nickjillings@1862 | 5 } |
nickjillings@1862 | 6 catch(Exception $e){ |
nickjillings@1862 | 7 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini |
nickjillings@1862 | 8 } |
b@1508 | 9 header('Access-Control-Allow-Origin: *'); |
nickjillings@1510 | 10 header("Content-type: text/xml"); |
b@1478 | 11 $postText = file_get_contents('php://input'); |
nickjillings@1466 | 12 $sha1_hash = sha1($postText); |
b@1478 | 13 $datetime = date('ymdHis'); |
nickjillings@1466 | 14 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
b@1478 | 15 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
nickjillings@1510 | 16 if ($fileHandle == FALSE) |
nickjillings@1510 | 17 { |
nickjillings@1510 | 18 // Filehandle failed |
nickjillings@1510 | 19 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nickjillings@1510 | 20 echo $xml; |
nickjillings@1510 | 21 return; |
nickjillings@1510 | 22 } |
nickjillings@1510 | 23 $wbytes = fwrite($fileHandle, $postText); |
giuliomoro@1856 | 24 if ($wbytes === FALSE) |
nickjillings@1510 | 25 { |
nickjillings@1510 | 26 // FileWrite failed |
nickjillings@1510 | 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nickjillings@1510 | 28 echo $xml; |
nickjillings@1510 | 29 return; |
nickjillings@1510 | 30 } |
b@1478 | 31 fclose($fileHandle); |
nickjillings@1510 | 32 |
nickjillings@1510 | 33 // Return JSON confirmation data |
nickjillings@1510 | 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nickjillings@1510 | 35 echo $xml; |
giuliomoro@1855 | 36 ?> |