annotate save.php @ 1451:f6a6b7fd4041

Fixing Win/OSX differences for APE slider, unstable.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Mon, 23 Nov 2015 17:44:25 +0000
parents
children 1b6fa37d46a4
rev   line source
nickjillings@1451 1 <?php
nickjillings@1451 2 header('Access-Control-Allow-Origin: *');
nickjillings@1451 3 header("Content-type: text/xml");
nickjillings@1451 4 $postText = file_get_contents('php://input');
nickjillings@1451 5 $datetime = date('ymdHis');
nickjillings@1451 6 $xmlfile = "save".$datetime."-".generateRandomString(6).".xml";
nickjillings@1451 7 $fileHandle = fopen("saves/".$xmlfile, 'w');
nickjillings@1451 8 if ($fileHandle == FALSE)
nickjillings@1451 9 {
nickjillings@1451 10 // Filehandle failed
nickjillings@1451 11 $xml = '<response state="error"><message>Could not open file</message></response>';
nickjillings@1451 12 echo $xml;
nickjillings@1451 13 return;
nickjillings@1451 14 }
nickjillings@1451 15 $wbytes = fwrite($fileHandle, $postText);
nickjillings@1451 16 if ($wbytes == FALSE)
nickjillings@1451 17 {
nickjillings@1451 18 // FileWrite failed
nickjillings@1451 19 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>';
nickjillings@1451 20 echo $xml;
nickjillings@1451 21 return;
nickjillings@1451 22 }
nickjillings@1451 23 fclose($fileHandle);
nickjillings@1451 24
nickjillings@1451 25 // Return JSON confirmation data
nickjillings@1451 26 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>';
nickjillings@1451 27 echo $xml;
nickjillings@1451 28
nickjillings@1451 29 // Random String generator from http://stackoverflow.com/questions/4356289/php-random-string-generator
nickjillings@1451 30 function generateRandomString($length = 10) {
nickjillings@1451 31 $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
nickjillings@1451 32 $charactersLength = strlen($characters);
nickjillings@1451 33 $randomString = '';
nickjillings@1451 34 for ($i = 0; $i < $length; $i++) {
nickjillings@1451 35 $randomString .= $characters[rand(0, $charactersLength - 1)];
nickjillings@1451 36 }
nickjillings@1451 37 return $randomString;
nickjillings@1451 38 }
nickjillings@1451 39 ?>