Post valuse and upload Image to php server in android

Posted by lawat on Stack Overflow See other posts from Stack Overflow or by lawat
Published on 2011-01-07T07:45:07Z Indexed on 2011/01/07 7:53 UTC
Read the original article Hit count: 188

Filed under:
|
|
|
|

I am trying to upload image from android phone to php server with additional values,the method is post my php file look like this

if($_POST['val1']){
  if($_POST['val2']){
     if($_FILE['image']){
      ...... 
    }
  }
}else{
echo "Value not found";
}

I am doing is

URL url=new URL("http://www/......../myfile.php");
HttpURLConnection con=(HttpURLConnection) url.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestMethod("POST");//Enable http POST
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Content-Type", "multipart/form-data;boundary="+"****");
connection.setRequestProperty("uploaded_file", imagefilePath);
DataOutputStream ostream = new DataOutputStream( con.getOutputStream());
String res=("Content-Disposition: form-data; name=\"val1\""+val1+"****"+
"Content-Disposition: form-data; name=\"val2\""+val2+"****"
"Content-Disposition: form-data; name=\"image\";filename=\"" + imagefilePath +"\""+"****");
outputStream.writeBytes(res);

my actual problem is values are not posting so first if condition get false and else section is executed that is it give value not found please help me

© Stack Overflow or respective owner

Related posts about java

Related posts about php