Note that there are some explanatory texts on larger screens.

plurals
  1. POphp for receiving image and text from MultipartEntity
    text
    copied!<p>I'm trying to upload an image and some text via MultipartEntity. I can upload and receive the image, but when I try to add a Stringbody I cannot seem to receive it. Here's my android code</p> <pre><code>imports ETC... public void oncreate(){ ..... nameValuePairs.add(new BasicNameValuePair("image", exsistingFileName)); nameValuePairs.add(new BasicNameValuePair("title", "title")); } public void post(String url, List&lt;NameValuePair&gt; nameValuePairs) { HttpClient httpClient = new DefaultHttpClient(); HttpContext localContext = new BasicHttpContext(); HttpPost httpPost = new HttpPost(url); try { MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); for(int index=0; index &lt; nameValuePairs.size(); index++) { if(nameValuePairs.get(index).getName().equalsIgnoreCase("image")) { System.out.println("post - if"); // If the key equals to "image", we use FileBody to transfer the data entity.addPart( nameValuePairs.get(index).getName(), new FileBody(new File (nameValuePairs.get(index).getValue()))); } else { System.out.println("post - else"); // Normal string data entity.addPart(nameValuePairs.get(index).getName(), new StringBody(nameValuePairs.get(index).getValue())); } } System.out.println("post - done" + entity); httpPost.setEntity(entity); HttpResponse response = httpClient.execute(httpPost, localContext); } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>And my php:</p> <pre><code>&lt;?php $uploads_dir = 'uploads/'; $uploadname = $_FILES["image"]["name"]; $uploadtitle = $_FILES["title"]["title"]; move_uploaded_file($_FILES['image']['tmp_name'], $uploads_dir.$uploadname); file_put_contents($uploads_dir.'juhl.txt', print_r($uploadtitle, true)); ?&gt; </code></pre> <p>I've been around the other questions about MultipartEntity, but cannot seem to find the answer. I've tried sending just the Stringbody, but didn't have any succs in that either. I think the problem is serverside (in the PHP) but any suggestions are welcome. </p> <p>This is my first question in here - feel free to comment on form and clarity :-)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload