Mercurial > hg > webaudioevaluationtool
annotate save.php @ 556:80796ff2ae66 Dev_main
Actually the previous commit was broken. This contains a working and more elegant way of checking for the input file length. If the input file is empty, no error is triggered.
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 23 Feb 2016 14:39:06 +0000 |
parents | 4cc5bc731a3d |
children | 3ddf4feceab7 |
rev | line source |
---|---|
n@292 | 1 <?php |
b@343 | 2 header('Access-Control-Allow-Origin: *'); |
nicholas@345 | 3 header("Content-type: text/xml"); |
giuliomoro@534 | 4 error_reporting(0); |
n@292 | 5 $postText = file_get_contents('php://input'); |
nicholas@357 | 6 $sha1_hash = sha1($postText); |
n@292 | 7 $datetime = date('ymdHis'); |
nicholas@357 | 8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
n@292 | 9 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
nicholas@345 | 10 if ($fileHandle == FALSE) |
nicholas@345 | 11 { |
nicholas@345 | 12 // Filehandle failed |
nicholas@345 | 13 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@345 | 14 echo $xml; |
nicholas@345 | 15 return; |
nicholas@345 | 16 } |
nicholas@345 | 17 $wbytes = fwrite($fileHandle, $postText); |
giuliomoro@556 | 18 if ($wbytes === FALSE) |
nicholas@345 | 19 { |
nicholas@345 | 20 // FileWrite failed |
nicholas@345 | 21 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nicholas@345 | 22 echo $xml; |
nicholas@345 | 23 return; |
nicholas@345 | 24 } |
n@292 | 25 fclose($fileHandle); |
nicholas@345 | 26 |
nicholas@345 | 27 // Return JSON confirmation data |
nicholas@345 | 28 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nicholas@345 | 29 echo $xml; |
giuliomoro@555 | 30 ?> |