0
PHPを使用してAndroidからサーバーにファイルをアップロードするなど、誰でも自分のコード作業を手助けできますか?私はさまざまな方法で試しましたが、うまくいかないでしょう。私はHTTP Response 200を取得しますが、ファイルはサーバーにアップロードされません。PHP経由でAndroidからサーバーにファイルをアップロードする
私は、アップロードのために使用しているPHPスクリプトは次のとおりです。
<?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);
?>
私もHttpmime 4.0からマルチパートを使用してみましたが、それ文句を言わない仕事。
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();
}
}