1
내 안드로이드 응용 프로그램이 파일을 원격 PHP 서버에 성공적으로 보냅니다. 서버가 단순한 문자열을 다시 보내 응답을 알고 때까지Android : HttpResponse로 PHP 서버에서 파일 가져 오기
PHP 코드
// if a file was posted
if($_FILES && $_POST){
if(move_uploaded_file($file, $dir)) {
echo "File successfully sent to server.";
}
나는 코드의 평화와이 텍스트 답변을 얻을 수 있습니다
:
자바 코드
을HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
// get server response
if (resEntity != null) {
return EntityUtils.toString(resEntity).trim();
}
이제 간단한 텍스트 응답을 받고 싶지는 않지만 전체 파일. 나는 많은 경험을 가지고 있지 않고 붙어있어 : 확실히 바이트의 파일 크기가 아닌
PHP 코드
if(move_uploaded_file($app, $upload_file . $file_ending)) {
readfile($res_file); // read file and write it output buffer
}
자바 코드
HttpResponse response = httpClient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null)
return String.valueOf(resEntity.getContentLength());
getContentLength
반환 14 .
파일을 PHP 서버에서 어떻게 응답합니까?
이것은 작동합니다. 고마워. 설명해주십시오. 왜이 모든 헤더 행을 추가해야합니까? 왜 나는 단지 readfile ($ file)을 실행할 수 없습니까? – null
솔직히, 나는 당신이 그것을 필요로하지 않는다고 생각합니다. 디버깅에 도움이 될만한 것입니다. 내가 권하는 것은 파일을 보내기 전에 파일이 존재하는지 확인하는 것입니다. – erad
이 줄이 없으면 같은 오류가 발생합니다. 따라서 그들은 필요합니다. – null