I'm writing an app which should send a file to PHP server. Here is my code:
InputStream is = new FileInputStream(file);
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://majkelsoftgames.cba.pl/ser/server.php");
byte[] data = IOUtils.toByteArray(is);
InputStreamBody isb= new InputStreamBody(new ByteArrayInputStream(data), "file");
MultipartEntity multipartContent = new MultipartEntity();
multipartContent.addPart("file", isb);
postRequest.setEntity(multipartContent);
HttpResponse response = httpClient.execute(postRequest);
My problem is that I really dont have experience in PHP and I dont know how to pick up this file on PHP side. I found some code:
<?php
$target_path = "./";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
}
else {
echo "There was an error uploading the file, please try again!";
}
?>
But it does not work. Can someone explain me how can I simply pick up fine on PHP side?