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