Hi,
I want to upload multiple images selected from gallery and upload it to server along with other data.
Other data will be inserted into database in server.
Till now what i have done is firing http url in a for loop till number of images. All images are getting uploaded.
But, problem is, so many times the data also have been inserted into table.
What I want is, to insert data only once and upload number of images selected into a folder in server.
JAVA code:
PHP code:
I want to upload multiple images selected from gallery and upload it to server along with other data.
Other data will be inserted into database in server.
Till now what i have done is firing http url in a for loop till number of images. All images are getting uploaded.
But, problem is, so many times the data also have been inserted into table.
What I want is, to insert data only once and upload number of images selected into a folder in server.
JAVA code:
Code:
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(URL)
try
{
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
entityBuilder.addTextBody("a", "apple");
entityBuilder.addTextBody("b", "banana");
entityBuilder.addTextBody("c", "cake");
for (String element : list) {
File bin = new File(element);
FileBody bin1 = new FileBody(bin);
entityBuilder.addPart("ImageEncoded",bin1 );
HttpEntity entity = entityBuilder.build();
post.setEntity(entity);
response = client.execute(post);
}
httpEntity = response.getEntity();
result = EntityUtils.toString(httpEntity);
}
PHP code:
Code:
<?php
$target_path1 = "uploads/";
$a = $_POST['a'];
$b = $_POST['b'];
$c = $_POST['c'];
$fname = $_FILES['ImageEncoded']['name'];
$query1 = mysql_query("INSERT INTO demo VALUES('','$a','$b','$c','$fname')");
$target_path1 = $target_path1 . basename( $_FILES['ImageEncoded']['name']);
if(move_uploaded_file($_FILES['ImageEncoded']['tmp_name'], $target_path1)) {
echo "Success";
} else{
echo "Fail";
}
?>
Comment