I have taken the photo from camera and getting the image from sdcard also . Here i have to upload this photo to php server. How can i do ??? please give me a solution.
EDIT:
As am getting the string value of image path is : /mnt/sdcard/DCIM/Camera/1382769609416.jpg
I have to insert the url of these image to my php server .
In my database the value is inserted on the field like :
images/trucks/mnt/sdcard/DCIM/Camera/1382769609416.jpg
But image is not upload to my php server.I have checked on "images/trucks/" this path.
This is my server side php code:
$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') ");
what's wrong in this code ?? please provide me a solution ???
Why that image is not upload from android to that folder ?? Please verify my code and give me a solution ??? But the path is correctly stored on that database.
This is my android side code:
In DetailsSpecification.java :
static String CapturedImageDetails;
String Path = cursor.getString(file_ColumnIndex);
CapturedImageDetails = Path;
In 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);
}
EDIT:
am getting the error when click submit button android form:
Notice: Undefined index: TRUCK_PHOTO in /opt/lampp/htdocs/ImageAndroid/imageupload.php on line 25
Notice: Undefined index: TRUCK_PHOTO in /opt/lampp/htdocs/ImageAndroid/imageupload.php on line 26
the 25 and 26 th line is :
$name = $_FILES['TRUCK_PHOTO']['name'];
$tmp_name = $_FILES['TRUCK_PHOTO']['tmp_name'];