Upload a file from Android to the server via PHP
<p>Can anyone help me to make my code work, i.e. upload a file from Android to the server via PHP? I tried it in many different ways but it won't work. I get HTTP Response 200 but the files aren't uploaded on server.</p>

<p>The PHP script I'm using for upload is:</p>

<pre><code>&lt;?php
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['uploaded_file']['name']);
if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
?&gt;
</code></pre>

<p>I also tried using multipart from Httpmime 4.0 but it wont work.</p>

<pre><code>public void uploadFile(String path)
{
    File file = new File(path);
    try {
        HttpClient client = new DefaultHttpClient();
        String postURL = upLoadServerUri;
        HttpPost post = new HttpPost(postURL);
        FileBody bin = new FileBody(file);
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        reqEntity.addPart("uploaded_file", bin);
        post.setEntity(reqEntity);
        HttpResponse response = client.execute(post);
        HttpEntity resEntity = response.getEntity();
        if (resEntity != null) {
            Log.i("RESPONSE Wahaj: ","Code : "+ EntityUtils.toString(resEntity));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
</code></pre>