android-async-http 上传图片到 php 服务器

android-async-http uploading image to php server

我整天都在研究如何将图像从我的应用程序上传到服务器端。 我已经完成了移动应用程序方面

public static void postImage(String ImageLink){
    RequestParams params = new RequestParams();
    params.put("uploaded_file[name]", "MyImageName");
    try {
        params.put("uploaded_file[image]", new File(ImageLink));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    AsyncHttpClient client = new AsyncHttpClient();
    client.post(MY_PHP_FILE_LINK, params, new AsyncHttpResponseHandler() {

        @Override
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
            System.out.println("statusCode "+statusCode);//statusCode 200
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

        }
    });
}

和我的 php 边码

<?php

$file_path = "/uploads/";

$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
    echo "success";
} else{
    echo "fail";
}?>

但即使 statusCode 正常,我也无法在服务器上找到图像

有什么问题??我的 php 代码错了吗?

我已经解决了这个问题,它在我的 RequestParams 中我试图更改文件名,但似乎我做不到,所以我更改了我的代码并且它工作正常

public static void postImage(String ImageLink){
RequestParams params = new RequestParams();
try {
    params.put("uploaded_file", new File(ImageLink));
} catch (FileNotFoundException e) {
    e.printStackTrace();
}
AsyncHttpClient client = new AsyncHttpClient();
client.post(MY_PHP_FILE_LINK, params, new AsyncHttpResponseHandler() {

    @Override
    public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
        System.out.println("statusCode "+statusCode);//statusCode 200
    }

    @Override
    public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {

    }
});
}