Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. private void uploadImage(){
  2. //Showing the progress dialog
  3. final ProgressDialog loading = ProgressDialog.show(this, "Uploading...", "Please wait...", false, false);
  4. StringRequest stringRequest = new StringRequest(Request.Method.POST, UPLOAD_URL,
  5. new Response.Listener<String>() {
  6. @Override
  7. public void onResponse(String s) {
  8. //Disimissing the progress dialog
  9. loading.dismiss();
  10. //Showing toast message of the response
  11. Toast.makeText(MainActivity.this, "uploaded" , Toast.LENGTH_LONG).show();
  12. }
  13. },
  14. new Response.ErrorListener() {
  15. @Override
  16. public void onErrorResponse(VolleyError volleyError) {
  17. //Dismissing the progress dialog
  18. loading.dismiss();
  19.  
  20. //Showing toast
  21. Toast.makeText(MainActivity.this, volleyError.getMessage().toString(), Toast.LENGTH_LONG).show();
  22. }
  23. }){
  24. @Override
  25. protected Map<String, String> getParams() throws AuthFailureError {
  26. //Converting Bitmap to String
  27. String image = getStringImage(bitmap);
  28.  
  29. //Getting Image Name
  30. String name = editTextName.getText().toString().trim();
  31.  
  32. //Creating parameters
  33. Map<String,String> params = new Hashtable<String, String>();
  34.  
  35. //Adding parameters
  36. params.put(KEY_IMAGE, image);
  37. params.put(KEY_NAME, "name");
  38.  
  39. //returning parameters
  40. return params;
  41. }
  42. };
  43.  
  44. //Creating a Request Queue
  45. RequestQueue requestQueue = Volley.newRequestQueue(this);
  46.  
  47. //Adding request to the queue
  48. requestQueue.add(stringRequest);
  49. }
  50.  
  51. <?php
  52.  
  53. $host="localhost"; //replace with database hostname
  54. $username="root"; //replace with database username
  55. $password=""; //replace with database password
  56. $db_name="mydb"; //replace with database name
  57.  
  58. $con=mysql_connect($host,$username,$password);
  59. $db=mysql_select_db($db_name);
  60.  
  61. $name = $_REQUEST['name']; //image name
  62. $image = $_REQUEST['image']; //image in string format
  63. $user=$_REQUEST['User_ID'];
  64.  
  65. $decodedImage = base64_decode($image);
  66. $image_file=time().rand(1111,9999);
  67. $name=$name.$image_file;
  68.  
  69. $base_path='/var/www/html/uploads/';
  70. file_put_contents($base_path.$name.".jpg", $decodedImage);
  71.  
  72. mysql_query("INSERT into `image`(`img`,`User_ID`,`date`) values ('".$image_file.".jpg','$user',now() )");
  73. echo mysql_insert_id();
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement