php怎么应用和web服务器分开,php – 如何让Android应用程序通过互联网与Web服务器通信?...

我有一个应用程序的想法,我正在学习

Android开发.我非常熟悉创建简单的独立应用程序.

我也熟悉PHP和虚拟主机.

我想做的是,让一个Android应用程序通过互联网将图像发送到服务器,并使服务器返回一个处理过的图像.我不知道我是怎么做到的.

你能否告诉我如何实现这个目标或者我应该研究哪些主题?另外,我可以使用哪些脚本在Web服务器上进行处理?特别是,我可以使用PHP还是Java?

谢谢!

For Image Uploading

///Method Communicate with webservice an return Yes if Image uploaded else NO

String executeMultipartPost(Bitmap bm,String image_name) {

String resp = null;

try {

ByteArrayOutputStream bos = new ByteArrayOutputStream();

bm.compress(CompressFormat.JPEG, 75, bos);

byte[] data = bos.toByteArray();

HttpClient httpClient = new DefaultHttpClient();

HttpPost postRequest = new HttpPost("domain.com/upload_image.php");

ByteArrayBody bab = new ByteArrayBody(data, image_name);

MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

reqEntity.addPart("uploaded", bab);

reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));

postRequest.setEntity(reqEntity);

HttpResponse response = httpClient.execute(postRequest);

BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));

String sResponse;

StringBuilder s = new StringBuilder();

while ((sResponse = reader.readLine()) != null) {

s = s.append(sResponse);

}

resp=s.toString();

} catch (Exception e) {

// handle exception here

Log.e(e.getClass().getName(), e.getMessage());

}

return resp;

}

//PHP Code

$target = "upload/";

$target = $target . basename( $_FILES['uploaded']['name']) ;

$ok=1;

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))

{

echo "yes";

}

else {

echo "no";

}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值