我已经从相机拍摄照片并从 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上传到该文件夹?请验证我的代码并给我一个解决方案???但路径已正确存储在该数据库中。
这是我的安卓端代码:
在DetailsSpecification .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'];