This is a simple way of posting files from Android.
String url = "http://yourserver.com/upload.php"; File file = new File("myfileuri"); try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1); reqEntity.setContentType("binary/octet-stream"); reqEntity.setChunked(true); // Send in multiple parts if needed httppost.setEntity(reqEntity); HttpResponse response = httpclient.execute(httppost); //Do something with response... } catch (Exception e) { e.printStackTrace(); } What I want to do is add more POST variables to my request. How do I do that? While uploading plain strings in POST request, we use URLEncodedFormEntity.
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); Whereas while uploading files, we use InputStreamEntity.
Also, how do I specifically upload this file to $_FILES['myfilename']?