-1

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'];
Jayyrus
  • 12,961
  • 41
  • 132
  • 214
user2218667
  • 607
  • 6
  • 25
  • 46
  • Seems like you have to use google. – Selvin Oct 24 '13 at 13:07
  • @Selvin i searched google and done the code like above. But i didn't get the path of captured photo url . Please visit the my post once again and give me a solution yaar – user2218667 Oct 24 '13 at 13:13
  • 1
    You need to decode from base64 back to bytes array on php side or use multipart – Selvin Oct 24 '13 at 13:16
  • yes you need to use decode http://fr2.php.net/fr/base64_decode but still will work just for small size pic I recomend you to use multipart http request – Simo Oct 24 '13 at 13:24
  • Please post the Java code that you are using to push the image to the server. – Matt Clark Nov 05 '13 at 04:46
  • @MattClark i have posted with java and server side coe.please verify it. – user2218667 Nov 05 '13 at 04:51
  • What is 'DetailsSpecification.CapturedImageDetails'? – Matt Clark Nov 05 '13 at 04:55
  • @MattClark that's the image path getting from sdcard.mnt/sdcard/DCIM/Camera/1382769609416.jpg – user2218667 Nov 05 '13 at 05:03
  • See, you set a NameValuePair for the file path, but you never actually send the image itself. You neec to encode the image, and add it as another NameValuePair. – Matt Clark Nov 05 '13 at 05:28
  • @MattClark if i have to use blob means i have to encode the image.but here am getting the image path as string value only. Then why i have to encode the image ? Please give me a clarification about this ??? – user2218667 Nov 06 '13 at 04:07

1 Answers1

1

Use the following code to convert bitmap image to String:

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;
}
Karan Sharma
  • 2,353
  • 4
  • 28
  • 46