Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void uploadImage(){
- //Showing the progress dialog
- final ProgressDialog loading = ProgressDialog.show(this, "Uploading...", "Please wait...", false, false);
- StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
- new Response.Listener<String>() {
- @Override
- public void onResponse(String s) {
- //Disimissing the progress dialog
- loading.dismiss();
- //Showing toast message of the response
- Toast.makeText(MainActivity.this, "uploaded" , Toast.LENGTH_LONG).show();
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError volleyError) {
- //Dismissing the progress dialog
- loading.dismiss();
- //Showing toast
- Toast.makeText(MainActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
- }
- }){
- @Override
- protected Map<String, String> getParams() throws AuthFailureError {
- //Converting Bitmap to String
- String image = getStringImage(bitmap);
- //Getting Image Name
- String name = editTextName.getText().toString().trim();
- //Creating parameters
- Map<String,String> params = new Hashtable<String, String>();
- //Adding parameters
- params.put(KEY_IMAGE, image);
- params.put(KEY_NAME, "name");
- //returning parameters
- return params;
- }
- };
- //Creating a Request Queue
- RequestQueue requestQueue = Volley.newRequestQueue(this);
- //Adding request to the queue
- requestQueue.add(stringRequest);
- }
- <?php
- $host="localhost"; //replace with database hostname
- $username="root"; //replace with database username
- $password=""; //replace with database password
- $db_name="mydb"; //replace with database name
- $con=mysql_connect($host,$username,$password);
- $db=mysql_select_db($db_name);
- $name = $_REQUEST['name']; //image name
- $image = $_REQUEST['image']; //image in string format
- $user=$_REQUEST['User_ID'];
- $decodedImage = base64_decode($image);
- $image_file=time().rand(1111,9999);
- $name=$name.$image_file;
- $base_path='/var/www/html/uploads/';
- file_put_contents($base_path.$name.".jpg", $decodedImage);
- mysql_query("INSERT into `image`(`img`,`User_ID`,`date`) values ('".$image_file.".jpg','$user',now() )");
- echo mysql_insert_id();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement