用PHP从Android发送带有注释的图像
我想从Android设备向PHP服务器发送一个带有一些注释的图像。我想使用JSON来交换数据。我看了很多地方,但没有得到正确的暗示。有人能给我们一些建议,让它与PHP一起工作吗 我不想使用base65,因为它会增加数据负载,图像大小也是一个问题。请提出您的想法和正确的发展方法 我的Android代码:用PHP从Android发送带有注释的图像,php,android,json,image,Php,Android,Json,Image,我想从Android设备向PHP服务器发送一个带有一些注释的图像。我想使用JSON来交换数据。我看了很多地方,但没有得到正确的暗示。有人能给我们一些建议,让它与PHP一起工作吗 我不想使用base65,因为它会增加数据负载,图像大小也是一个问题。请提出您的想法和正确的发展方法 我的Android代码: // Building Parameters List<NameValuePair> params = new ArrayList<Name
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("price", price));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("image","/sdcard/DCIM/android_1.png"));
// getting JSON Object
JSONObject json = jsonParser.makeHttpRequest(url_create_product,"POST", params);
// check log cat fro response
Log.d("Create Response", json.toString());
// check for success tag
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully created product
Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
startActivity(i);
// closing this screen
finish();
} else {
// failed to create product
}
} catch (JSONException e) {
e.printStackTrace();
}
我不确定如何使用JSON传递此多部分请求:
//获取JSON对象JSONObject json=jsonParser.makeHttpRequest(url\u create\u product,“POST”,params) 以及如何在PHP中将其作为图像读取。无图像PHP工作代码,如下所示:
<?php
/*
* Following code will create a new product row
* All product details are read from HTTP Post Request
*/
// array for JSON response
$response = array();
$target_path1 = "uploads/";
// check for required fields
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {
$name = $_POST['name'];
$price = $_POST['price'];
$description = $_POST['description'];
//I have data from android here now but How I can read image here ?
我从未使用JSON传递图像,只传递文本,但你可以使用android通过HTTP发布信息。查看本教程,它帮助了我我们将尝试此方法,但我不知道如何将“文本”与图像一起发送?为此,您需要使用JSON。与android相比,您的大部分工作都依赖于PHP。您需要做的是用JSON传递文本,并将图像作为post传递
<?php
/*
* Following code will create a new product row
* All product details are read from HTTP Post Request
*/
// array for JSON response
$response = array();
$target_path1 = "uploads/";
// check for required fields
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {
$name = $_POST['name'];
$price = $_POST['price'];
$description = $_POST['description'];
//I have data from android here now but How I can read image here ?