-1

我已经从相机拍摄照片并从 sdcard 获取图像。在这里,我必须将这张照片上传到 php 服务器。我能怎么做 ???请给我一个解决方案。

编辑:

获取图像路径的字符串值为:/mnt/sdcard/DCIM/Camera/1382769609416.jpg

我必须将这些图像的 url 插入我的 php 服务器。

在我的数据库中,值被插入到如下字段中:

images/trucks/mnt/sdcard/DCIM/Camera/1382769609416.jpg

但是图像没有上传到我的php服务器。我已经检查了“图像/卡车/”这个路径。

这是我的服务器端 php 代码:

$upload_dir = 'images/trucks/';
$name = $_FILES['TRUCK_PHOTO']['name'];
$tmp_name = $_FILES['TRUCK_PHOTO']['tmp_name'];
 $ext = pathinfo($name, PATHINFO_EXTENSION);
 $file_path=$upload_dir.$_POST['TRUCK_PHOTO'].".".$ext;
 move_uploaded_file($tmp_name, $file_path);
$query = mysqli_query($connect, "insert into tw_trucks (TRUCK_PHOTO) values ('$file_path') ");

这段代码有什么问题?请给我一个解决方案???

为什么该图像没有从android上传到该文件夹​​?请验证我的代码并给我一个解决方案???但路径已正确存储在该数据库中。

这是我的安卓端代码:

DetailsS​​pecification .java 中:

static String CapturedImageDetails;
String Path = cursor.getString(file_ColumnIndex);
             CapturedImageDetails = Path;

AvailableLocation .java 中:

  class UploadPhotoDetails extends AsyncTask<Void, Void, String> {
String _response = "";
@Override
protected void onPreExecute() {
    super.onPreExecute();
    showDialog(DIALOG_LOADING);
}
@Override
protected String doInBackground(Void... params) {
_response = postData();
return _response;
} 
public String postData() {
    String res=null;
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://192.168.2.45/ImageAndroid/imageupload.php");
    try {
       nameValuePairs = new ArrayList<NameValuePair>();
       nameValuePairs.add(new BasicNameValuePair("TRUCK_PHOTO", DetailsSpecification.CapturedImageDetails));
       httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
       HttpResponse response = httpclient.execute(httppost);
       HttpEntity entity = response.getEntity();
       result_status = EntityUtils.toString(entity);
       res = response.toString();
    } catch (ClientProtocolException e) {
    } catch (IOException e) {}
   return res;
}
 @Override
 protected void onPostExecute(String result) {
   super.onPostExecute(result);
   dismissDialog(DIALOG_LOADING);
 }                   

编辑:

单击提交按钮android表单时出现错误:

注意:未定义索引:第25行/opt/lampp/htdocs/ImageAndroid/imageupload.php 中的TRUCK_PHOTO注意:第26/opt/lampp/htdocs/ImageAndroid/imageupload.php中未定义索引:TRUCK_PHOTO


第 25 和 26 行是:

 $name = $_FILES['TRUCK_PHOTO']['name'];
    $tmp_name = $_FILES['TRUCK_PHOTO']['tmp_name'];
4

1 回答 1

1

使用以下代码将位图图像转换为字符串:

public String BitMapToString(Bitmap bitmap) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
    byte[] b = baos.toByteArray();
    String strBitMap = Base64.encodeToString(b, Base64.DEFAULT);
    return strBitMap;
}
于 2013-10-24T13:31:10.963 回答