annotate save.php @ 1242:987ccc04250b

Session now performs intermediate saves on each advanceState trigger (page completions, survey completions). Specification projectReturn now "local" for presentation saving
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Wed, 09 Mar 2016 12:41:26 +0000
parents 8c56eda17acd
children 83b439322229
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');
n@1242 12 $file_key = $_GET['key'];
n@1242 13 $filename = "saves/save-".$file_key.".xml";
n@1242 14 $fileHandle = fopen($filename, 'w');
nicholas@748 15 if ($fileHandle == FALSE)
nicholas@748 16 {
nicholas@748 17 // Filehandle failed
nicholas@748 18 $xml = '<response state="error"><message>Could not open file</message></response>';
nicholas@748 19 echo $xml;
nicholas@748 20 return;
nicholas@748 21 }
nicholas@748 22 $wbytes = fwrite($fileHandle, $postText);
giuliomoro@1215 23 if ($wbytes === FALSE)
nicholas@748 24 {
nicholas@748 25 // FileWrite failed
nicholas@748 26 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nicholas@748 27 echo $xml;
nicholas@748 28 return;
nicholas@748 29 }
BrechtDeMan@715 30 fclose($fileHandle);
nicholas@748 31
nicholas@748 32 // Return JSON confirmation data
nicholas@748 33 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nicholas@748 34 echo $xml;
giuliomoro@1214 35 ?>