annotate save.php @ 1883:b7db6a837242

Session now performs intermediate saves on each advanceState trigger (page completions, survey completions). Specification projectReturn now "local" for presentation saving
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 09 Mar 2016 12:41:26 +0000
parents 059cac752536
children 83b439322229
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@1883 12 $file_key = $_GET['key'];
nickjillings@1883 13 $filename = "saves/save-".$file_key.".xml";
nickjillings@1883 14 $fileHandle = fopen($filename, 'w');
nickjillings@1510 15 if ($fileHandle == FALSE)
nickjillings@1510 16 {
nickjillings@1510 17 // Filehandle failed
nickjillings@1510 18 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1510 19 echo $xml;
nickjillings@1510 20 return;
nickjillings@1510 21 }
nickjillings@1510 22 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@1856 23 if ($wbytes === FALSE)
nickjillings@1510 24 {
nickjillings@1510 25 // FileWrite failed
nickjillings@1510 26 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1510 27 echo $xml;
nickjillings@1510 28 return;
nickjillings@1510 29 }
b@1478 30 fclose($fileHandle);
nickjillings@1510 31
nickjillings@1510 32 // Return JSON confirmation data
nickjillings@1510 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1510 34 echo $xml;
giuliomoro@1855 35 ?>