Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. package com.example.asynchttpclientex;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5.  
  6. import org.apache.http.Header;
  7.  
  8. import android.os.Bundle;
  9. import android.support.v7.app.ActionBarActivity;
  10. import android.util.Log;
  11. import android.view.View;
  12. import android.view.View.OnClickListener;
  13. import android.widget.Button;
  14. import android.widget.Toast;
  15.  
  16. import com.loopj.android.http.AsyncHttpClient;
  17. import com.loopj.android.http.AsyncHttpResponseHandler;
  18. import com.loopj.android.http.RequestParams;
  19.  
  20. public class MainActivity extends ActionBarActivity {
  21.  
  22. Button a;
  23. protected void onCreate(Bundle savedInstanceState) {
  24. super.onCreate(savedInstanceState);
  25. setContentView(R.layout.activity_main);
  26.  
  27. a=(Button)findViewById(R.id.b);
  28.  
  29. a.setOnClickListener(new OnClickListener() {
  30.  
  31. @Override
  32. public void onClick(View v) {
  33. // TODO Auto-generated method stub
  34. String imagePath="file://sdcard/Images/tempge.jpg";
  35. AsyncHttpClient client = new AsyncHttpClient();
  36. File myFile = new File(imagePath);
  37. RequestParams params = new RequestParams();
  38. try {
  39. params.put("img", myFile);
  40. params.put("action", "hello data");
  41.  
  42. client.post("http://xxxxx.com/android/adem.php", params, new AsyncHttpResponseHandler() {
  43.  
  44. @Override
  45. public void onStart() {
  46. super.onStart();
  47. }
  48.  
  49. @Override
  50. public void onFailure(int arg0, Header[] arg1, byte[] arg2,
  51. Throwable arg3) {
  52. // TODO Auto-generated method stub
  53. Toast.makeText(getApplicationContext(), "failure...!", Toast.LENGTH_LONG).show();
  54. }
  55.  
  56. @Override
  57. public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
  58. // TODO Auto-generated method stub
  59. Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();
  60. }
  61.  
  62. });
  63. } catch(FileNotFoundException e) {
  64. Log.d("MyApp", "File not found!!!" + imagePath);
  65. }
  66.  
  67. }
  68. });
  69. }
  70. }
  71.  
  72. $target_path1 = "upload_image/";
  73. $randno=mt_rand(1,15000);
  74.  
  75. /* Add the original filename to our target path.
  76. Result is "uploads/filename.extension" */
  77.  
  78.  
  79. $target_path2 = $target_path1 . basename($randno.$_FILES['img']['name']);
  80. if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path2)) {
  81. echo "The first file ". basename($randno. $_FILES['uploadedfile1']['name']).
  82. " has been uploaded.";
  83.  
  84. $thumbimage1="http://www.xxxxx.com/android/".$target_path2;
  85.  
  86.  
  87. } else{
  88. echo "There was an error uploading the file, please try again!";
  89. echo "filename: " . basename( $_FILES['uploadedfile1']['name']);
  90. echo "target_path: " .$target_path2;
  91. }
  92.  
  93. $proj_name = $_POST['action'];
  94.  
  95. $con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
  96. mysql_select_db("xxxxx_nikapp");
  97. $query = mysql_query("insert into sfc(name, contact_no, lr_no, details) values ('$proj_name','$proj_name','$proj_name','$thumbimage1')");
  98.  
  99.  
  100. mysql_close();
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement