Wie hoch ein aufgenommenes Bild mit android-Gerät, um mysql-Datenbank mit php?

Ich bin Neuling auf android, ich bin versucht, ein Bild hochzuladen auf dem mysql-server. In meiner app habe ich die Schaltfläche Bild hochladen, Wann immer Benutzer klicken Sie auf die Schaltfläche es öffnet sich die Kamera in android-Gerät. Ich bin erfolgreich erste aufgenommene Bild mit der Kamera in der Bildansicht , ich möchte speichern Sie dieses Bild in der mysql-Datenbank mit php, ich bin erfolgreich eine Verbindung zur Datenbank mit php und hochladen wenige Felder eingetragen in das edittext aber ich kann nicht in der Lage, um das Bild hochzuladen. Ich habe es gegoogelt, aber alle sind mit dem Bild hochladen mit url. Aber in meinem Fall ist es etwas anders Aussehen in meinem code und bitte helfen Sie mir.

FormActivity.java

public class FormActivity extends Activity {

final Context context = this;
private ProgressDialog pDialog;
static final String TAG_SUCCESS = "success";
JSONParser jsonParser = new JSONParser();
private static String url_submit_hourly = "http://www.example.com/FacebookApp/submit.php";

EditText tasktitle;

String title;
Button upload, submit;

private static final int CAMERA_REQUEST = 1888;
private ImageView imageView;
byte[] byteArray;
protected static final int TAKE_PHOTO_CODE = 0;
byte[] imgbyte;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.submit_hourly);

    tasktitle = (EditText) findViewById(R.id.etfirst);

    submit = (Button) findViewById(R.id.submit);
    submit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new BookSlot().execute();
        }
    });

    upload = (Button) findViewById(R.id.upload);
    this.imageView = (ImageView) this.findViewById(R.id.image);
    upload.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
            startActivityForResult(intent, CAMERA_REQUEST);
        }

    });

}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
        Bitmap photo = (Bitmap) data.getExtras().get("data");
        imageView.setImageBitmap(photo);

    }

}

class BookSlot extends AsyncTask<String, String, String> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(FormActivity.this);
        pDialog.setMessage("Creating Hourly..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }

    @Override
    protected String doInBackground(String... args) {


        title = tasktitle.getText().toString();


        List<NameValuePair> params = new ArrayList<NameValuePair>();

        params.add(new BasicNameValuePair("task_tilte", title));

        JSONObject json = jsonParser.makeHttpRequest(url_submit_hourly,
                "POST", params);

        //check log cat fro response
        Log.d("Create Response", json.toString());

        //check for success tag
        try {
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                //successfully created product
                Intent i = new Intent(getApplicationContext(),
                        FacebookLoginActivity.class);

                startActivity(i);

                //closing this screen
                finish();
            } else {
                //failed to create product
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     * **/
    protected void onPostExecute(String file_url) {
        //dismiss the dialog once done
        pDialog.dismiss();
    }

}

}

submit.php

<?php


//array for JSON response
$response = array();

//check for required fields
if (isset($_POST['task_tilte'])) {

$title = $_POST['task_tilte'];


//include db connect class
define('__ROOT__', dirname(dirname(__FILE__))); 
require_once(__ROOT__.'/FacebookApp/db_connect.php'); 

//connecting to db
$db = new DB_CONNECT();

//mysql inserting a new row
$result = mysql_query("INSERT INTO                       task_table(task_tilte)     VALUES('$title')");

//check if row inserted or not
if ($result) {
    //successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";

    //echoing JSON response
    echo json_encode($response);
} else {
    //failed to insert row
    $response["success"] = 0;
    $response["message"] = "Oops! An error occurred.";

    //echoing JSON response
    echo json_encode($response);
}
} else {
//required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

//echoing JSON response
echo json_encode($response);
}
?>

Bin ich nicht immer die Ahnung, wie man das speichern des Bildes in der Bildansicht auf die mysql-Datenbank.

Schreibe einen Kommentar