Mercurial > hg > webaudioevaluationtool
annotate save.php @ 1214:dc4300033afc
Added error check for empty file in save.php
author | Giulio Moro <giuliomoro@yahoo.it> |
---|---|
date | Tue, 23 Feb 2016 14:18:25 +0000 |
parents | 47bfd9594617 |
children | 5df87aa95395 |
rev | line source |
---|---|
BrechtDeMan@715 | 1 <?php |
BrechtDeMan@746 | 2 header('Access-Control-Allow-Origin: *'); |
nicholas@748 | 3 header("Content-type: text/xml"); |
giuliomoro@1088 | 4 error_reporting(0); |
BrechtDeMan@715 | 5 $postText = file_get_contents('php://input'); |
nicholas@829 | 6 $sha1_hash = sha1($postText); |
BrechtDeMan@715 | 7 $datetime = date('ymdHis'); |
nicholas@829 | 8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
BrechtDeMan@715 | 9 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
giuliomoro@1214 | 10 if (sizeof($postText) <= 1) |
giuliomoro@1214 | 11 { |
giuliomoro@1214 | 12 // Filehandle failed |
giuliomoro@1214 | 13 $xml = '<response state="error"><message>Input file empty</message></response>'; |
giuliomoro@1214 | 14 echo $xml; |
giuliomoro@1214 | 15 return; |
giuliomoro@1214 | 16 } |
nicholas@748 | 17 if ($fileHandle == FALSE) |
nicholas@748 | 18 { |
nicholas@748 | 19 // Filehandle failed |
nicholas@748 | 20 $xml = '<response state="error"><message>Could not open file</message></response>'; |
nicholas@748 | 21 echo $xml; |
nicholas@748 | 22 return; |
nicholas@748 | 23 } |
nicholas@748 | 24 $wbytes = fwrite($fileHandle, $postText); |
nicholas@748 | 25 if ($wbytes == FALSE) |
nicholas@748 | 26 { |
nicholas@748 | 27 // FileWrite failed |
nicholas@748 | 28 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
nicholas@748 | 29 echo $xml; |
nicholas@748 | 30 return; |
nicholas@748 | 31 } |
BrechtDeMan@715 | 32 fclose($fileHandle); |
nicholas@748 | 33 |
nicholas@748 | 34 // Return JSON confirmation data |
nicholas@748 | 35 $xml = '<response state="OK"><message>OK</message><file bytes="'.$wbytes.'">"saves/'.$xmlfile.'"</file></response>'; |
nicholas@748 | 36 echo $xml; |
giuliomoro@1214 | 37 ?> |