Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.asynchttpclientex;
- import java.io.File;
- import java.io.FileNotFoundException;
- import org.apache.http.Header;
- import android.os.Bundle;
- import android.support.v7.app.ActionBarActivity;
- import android.util.Log;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.Toast;
- import com.loopj.android.http.AsyncHttpClient;
- import com.loopj.android.http.AsyncHttpResponseHandler;
- import com.loopj.android.http.RequestParams;
- public class MainActivity extends ActionBarActivity {
- Button a;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- a=(Button)findViewById(R.id.b);
- a.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- String imagePath="file://sdcard/Images/tempge.jpg";
- AsyncHttpClient client = new AsyncHttpClient();
- File myFile = new File(imagePath);
- RequestParams params = new RequestParams();
- try {
- params.put("img", myFile);
- params.put("action", "hello data");
- client.post("http://xxxxx.com/android/adem.php", params, new AsyncHttpResponseHandler() {
- @Override
- public void onStart() {
- super.onStart();
- }
- @Override
- public void onFailure(int arg0, Header[] arg1, byte[] arg2,
- Throwable arg3) {
- // TODO Auto-generated method stub
- Toast.makeText(getApplicationContext(), "failure...!", Toast.LENGTH_LONG).show();
- }
- @Override
- public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
- // TODO Auto-generated method stub
- Toast.makeText(getApplicationContext(), "Success!", Toast.LENGTH_LONG).show();
- }
- });
- } catch(FileNotFoundException e) {
- Log.d("MyApp", "File not found!!!" + imagePath);
- }
- }
- });
- }
- }
- $target_path1 = "upload_image/";
- $randno=mt_rand(1,15000);
- /* Add the original filename to our target path.
- Result is "uploads/filename.extension" */
- $target_path2 = $target_path1 . basename($randno.$_FILES['img']['name']);
- if(move_uploaded_file($_FILES['uploadedfile1']['tmp_name'], $target_path2)) {
- echo "The first file ". basename($randno. $_FILES['uploadedfile1']['name']).
- " has been uploaded.";
- $thumbimage1="http://www.xxxxx.com/android/".$target_path2;
- } else{
- echo "There was an error uploading the file, please try again!";
- echo "filename: " . basename( $_FILES['uploadedfile1']['name']);
- echo "target_path: " .$target_path2;
- }
- $proj_name = $_POST['action'];
- $con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
- mysql_select_db("xxxxx_nikapp");
- $query = mysql_query("insert into sfc(name, contact_no, lr_no, details) values ('$proj_name','$proj_name','$proj_name','$thumbimage1')");
- mysql_close();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement