邮政值和上传图像到android的PHP服务器图像、邮政、上传、服务器

2023-09-13 01:45:03 作者:云朵和你.

我想从Android手机的PHP服务器附加值上传图片,该方法是POST 我的PHP文件看起来像这样

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";
}

我做的是

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

推荐答案

我发现我的问题的解决方案。我作出错误的线串RES =(......); 我还没有加入\ r \ n之后的每一个content.I有加它和我的code正常工作

I have found solution of my problem. I am making mistake at line string res=(" .... "); I have not adding "\r\n" after every content.I have add it and my code working properly

链接对我来说是非常有用的: 的http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_in_Java_ME

link is very useful for me : http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_in_Java_ME

谢谢主席先生对我的帮助

Thank you sir for helping me