問題描述
我正在嘗試使用附加值將圖像從 android 手機(jī)上傳到 php 服務(wù)器,方法是 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);
我的實(shí)際問題是沒有發(fā)布值,所以首先如果條件為假,否則執(zhí)行其他部分,即未找到值請(qǐng)幫幫我
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=(" .... "); 處犯了錯(cuò)誤我沒有在每個(gè)內(nèi)容之后添加 ".我已經(jīng)添加了它并且我的代碼可以正常工作
I have found solution of my problem. I am making mistake at line string res=(" .... "); I have not adding " " after every content.I have add it and my code working properly
鏈接對(duì)我非常有用:http://wiki.forum.nokia.com/index.php/HTTP_Post_multipart_file_upload_in_Java_ME
謝謝樓主幫助我
這篇關(guān)于在android中發(fā)布值并將圖像上傳到php服務(wù)器的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!