Mercurial > hg > webaudioevaluationtool
annotate save.php @ 2136:a55aa62ff3f9
Analysis: Added dynamic data sorting
author | Nicholas Jillings <nickjillings@users.noreply.github.com> |
---|---|
date | Wed, 24 Feb 2016 13:36:12 +0000 |
parents | 93a87f26323c |
children | 8c56eda17acd |
rev | line source |
---|---|
b@1478 | 1 <?php |
nickjillings@2129 | 2 try{ |
nickjillings@2129 | 3 date_default_timezone_get(); |
nickjillings@2129 | 4 } |
nickjillings@2129 | 5 catch(Exception $e){ |
nickjillings@2129 | 6 date_default_timezone_set('UTC'); // Sets to UTC if not specified anywhere in .ini |
nickjillings@2129 | 7 } |
b@1969 | 8 header('Access-Control-Allow-Origin: *'); |
nickjillings@1971 | 9 header("Content-type: text/xml"); |
giuliomoro@1304 | 10 error_reporting(0); |
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@1971 | 16 if ($fileHandle == FALSE) |
nickjillings@1971 | 17 { |
nickjillings@1971 | 18 // Filehandle failed |
nickjillings@1971 | 19 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nickjillings@1971 | 20 echo $xml; |
nickjillings@1971 | 21 return; |
nickjillings@1971 | 22 } |
nickjillings@1971 | 23 $wbytes = fwrite($fileHandle, $postText); |
giuliomoro@2123 | 24 if ($wbytes === FALSE) |
nickjillings@1971 | 25 { |
nickjillings@1971 | 26 // FileWrite failed |
nickjillings@1971 | 27 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nickjillings@1971 | 28 echo $xml; |
nickjillings@1971 | 29 return; |
nickjillings@1971 | 30 } |
b@1478 | 31 fclose($fileHandle); |
nickjillings@1971 | 32 |
nickjillings@1971 | 33 // Return JSON confirmation data |
nickjillings@1971 | 34 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nickjillings@1971 | 35 echo $xml; |
giuliomoro@2122 | 36 ?> |