This is a simple example to upload images to hosted server from android app with help of PHP script.
First of all we need to created the PHP script which is hosted in server.
uploadImage.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| <?php
//path starts from the default root directory
$target_path = "images/";
$base=$_REQUEST['image'];
$name=$_REQUEST['name'];
echo $base;
echo $name;
// base64 encoded utf-8 string
$binary=base64_decode($base);
// binary, utf-8 bytes
header('Content-Type: bitmap; charset=utf-8');
$file = fopen($target_path, 'wb');
$file = fopen($name, 'wb');
fwrite($file, $binary);
fclose($file);
copy($name,$target_path.$name);
?>
|
Then create an Android Application Project using eclipse or any other IDE.
After creating new android project open the activity_main.xml.
update the activity_main.xml with following code.