• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Take a picture from camera and send to php server

krishnaveni

Well-Known Member
Dec 16, 2011
158
0
chennai
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.

As am getting the string value of image path is : /mnt/sdcard/DCIM/Camera/1382769609416.jpg

I have to insert the url of this image to my php server .
In my database the value is inserted on the field like :
http://androidforums.com/images/trucks/mnt/sdcard/DCIM/Camera/1382769609416.jpg But image is not upload to my php server.I have checked on "http://androidforums.com/images/trucks/" this path.

This is my server side php code:

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') ");
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 :


[HIGH]
static String CapturedImageDetails;
String Path = cursor.getString(file_ColumnIndex);
CapturedImageDetails = Path;
[/HIGH]
In AvailableLocation.java :

[HIGH]
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);
[/HIGH]
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 :


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

[/HIGH]
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones