My android application successfully sends files to a remote php server. Until know the server responds by sending back a simple string:
PHP Code
// if a file was posted
if($_FILES && $_POST){
if(move_uploaded_file($file, $dir)) {
echo "File successfully sent to server.";
}
I can get this text answer with this peace of code:
Java Code
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
// get server response
if (resEntity != null) {
return EntityUtils.toString(resEntity).trim();
}
Now I don't want to get a simple text response, but i expect a whole file. I don't have much experience and got stuck:
PHP Code
if(move_uploaded_file($app, $upload_file . $file_ending)) {
readfile($res_file); // read file and write it output buffer
}
Java Code
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null)
return String.valueOf(resEntity.getContentLength());
getContentLength
returns 14, which is definitely not the file size in byte.
How do I get a file as response from a PHP server?