annotate save.php @ 1474:cb98283ece7e

Feature #1266: Checks for fragments fully played implemented
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Wed, 02 Dec 2015 12:05:08 +0000
parents 20268b33cfaa
children 888292c88c33
rev   line source
nickjillings@1453 1 <?php
nickjillings@1457 2 header('Access-Control-Allow-Origin: *');
nickjillings@1457 3 header("Content-type: text/xml");
nickjillings@1453 4 $postText = file_get_contents('php://input');
nickjillings@1466 5 $sha1_hash = sha1($postText);
nickjillings@1453 6 $datetime = date('ymdHis');
nickjillings@1466 7 $xmlfile = "save".$datetime."-".$sha1_hash.".xml";
nickjillings@1453 8 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1457 9 if ($fileHandle == FALSE)
nickjillings@1457 10 {
nickjillings@1457 11 // Filehandle failed
nickjillings@1457 12 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1457 13 echo $xml;
nickjillings@1457 14 return;
nickjillings@1457 15 }
nickjillings@1457 16 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1457 17 if ($wbytes == FALSE)
nickjillings@1457 18 {
nickjillings@1457 19 // FileWrite failed
nickjillings@1457 20 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1457 21 echo $xml;
nickjillings@1457 22 return;
nickjillings@1457 23 }
nickjillings@1453 24 fclose($fileHandle);
nickjillings@1457 25
nickjillings@1457 26 // Return JSON confirmation data
nickjillings@1457 27 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1457 28 echo $xml;
nickjillings@1453 29 ?>