Mercurial > hg > webaudioevaluationtool
comparison save.php @ 1856:96b83aa64be3
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@users.noreply.github.com> |
---|---|
date | Tue, 23 Feb 2016 14:39:06 +0000 |
parents | 03b876101f05 |
children | 585e06d319d2 |
comparison
equal
deleted
inserted
replaced
1855:03b876101f05 | 1856:96b83aa64be3 |
---|---|
5 $postText = file_get_contents('php://input'); | 5 $postText = file_get_contents('php://input'); |
6 $sha1_hash = sha1($postText); | 6 $sha1_hash = sha1($postText); |
7 $datetime = date('ymdHis'); | 7 $datetime = date('ymdHis'); |
8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; | 8 $xmlfile = "save".$datetime."-".$sha1_hash.".xml"; |
9 $fileHandle = fopen("saves/".$xmlfile, 'w'); | 9 $fileHandle = fopen("saves/".$xmlfile, 'w'); |
10 if (sizeof($postText) <= 1) | |
11 { | |
12 // Filehandle failed | |
13 $xml = '<response state="error"><message>Input file empty</message></response>'; | |
14 echo $xml; | |
15 return; | |
16 } | |
17 if ($fileHandle == FALSE) | 10 if ($fileHandle == FALSE) |
18 { | 11 { |
19 // Filehandle failed | 12 // Filehandle failed |
20 $xml = '<response state="error"><message>Could not open file</message></response>'; | 13 $xml = '<response state="error"><message>Could not open file</message></response>'; |
21 echo $xml; | 14 echo $xml; |
22 return; | 15 return; |
23 } | 16 } |
24 $wbytes = fwrite($fileHandle, $postText); | 17 $wbytes = fwrite($fileHandle, $postText); |
25 if ($wbytes == FALSE) | 18 if ($wbytes === FALSE) |
26 { | 19 { |
27 // FileWrite failed | 20 // FileWrite failed |
28 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; | 21 $xml = '<response state="error"><message>Could not write file "saves/'.$xmlfile.'"</message></response>'; |
29 echo $xml; | 22 echo $xml; |
30 return; | 23 return; |