I am trying to upload Image to the server, which I did and works very well. But the problem I ran into is the desire to upload an image, as well as pass some parameter with that image, such as Mobile Number ..
I am very new to android and also donβt know anything about PHP side coding. I tried the following code to load the image, I added a few more lines to pass the Mobile Number with this image. I really don't know if this is right or wrong, but please correct me if I am wrong ...
public class MainActivity extends Activity implements OnClickListener{ private TextView messageText; private Button uploadButton, btnselectpic; private ImageView imageview; private int serverResponseCode = 0; private ProgressDialog dialog = null; private String upLoadServerUri = null; private String imagepath=null; private String usernumber="3333333333"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); uploadButton = (Button)findViewById(R.id.uploadButton); messageText = (TextView)findViewById(R.id.messageText); btnselectpic = (Button)findViewById(R.id.button_selectpic); imageview = (ImageView)findViewById(R.id.imageView_pic); btnselectpic.setOnClickListener(this); uploadButton.setOnClickListener(this); upLoadServerUri = "http://XXX.XX.X.XXX/Images/UploadToServer.php"; } @Override public void onClick(View arg0) { if(arg0==btnselectpic) { Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Complete action using"), 1); } else if (arg0==uploadButton) { dialog = ProgressDialog.show(MainActivity.this, "", "Uploading file...", true);
This is server side code to save the image.
<?php $file_path = "uploads/"; $file_path = $file_path . basename( $_FILES['uploaded_file']['name']); if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) { echo "success"; } else{ echo "fail"; } ?>
Please tell me how can I get this mobile number on the server side?
source share