so I just created my first website and I'm using php file to communicate with my android app.. The android app is requesting for alot of data and the php is sending it back to it.
The only way I have found yet to send data from php to the android is via echo
I have alot of strings and pictures in my data and I seperate them all with ugly "BUFFER1"
style buffers between each data as it all comes out eventually as a long string combined together..
Here is an example:
<?php
$input_number = $_POST["In_Number"];
$path = ("Folder/" . $input_number);
$Data1 = file_get_contents($path . "/data1.txt");
$Data2 = file_get_contents($path . "/data2.txt");
$Data3 = file_get_contents($path . "/data3.txt");
echo $Data1;
echo "STREAMING_BUFFER";
echo $Data2;
echo "STREAMING_BUFFER";
echo $Data3;
echo "STREAMING_BUFFER";
...
// sending the pictures now (encoded..)
$pic_folder_path = ("Folder/" . $input_number . "/pics/");
$pics_pathes = array_diff(scandir($pic_folder_path), array('..', '.'));
foreach($pics_pathes as $pic_path){
$image = file_get_contents($pic_folder_path . $pic_path);
echo base64_encode($image);
echo "PICTURE_BUFFER";
}
echo "STREAMING_BUFFER";
// END
?>
The android to php communicate is much simpler.. I use the POST
method to send <key,value>
pairs and I can easily read them that way..
<?php
$name = $_POST["name"];
$image = $_POST["image"];
$decodedImage = base64_decode("$image");
file_put_contents("pictures/" . $name . ".JPG", $decodedImage);
?>
The name
is easily separated from the image
data.. and sure I could seperate that way much more data
Is there any similar way for the php to android way?
Thanks.