在android中上传多个图片

时间:2016-07-07 23:49:57

标签: php android file-upload upload image-uploading

此代码可以在1-40张图片之间上传,但不会超过这个,即使我尝试多次运行该功能。

有谁知道如何上传100-300张图片?甚至好几次。 感谢

Android应用程序代码

public void UploadToServer(final ArrayList<String> images, final String Name){
        RequestParams params = new RequestParams();
        AsyncHttpClient client = new AsyncHttpClient();

        params.put("Count" ,images.size());
        params.put("Name" , Name);

        File[] arr = new File[images.size()];

        for (int i = 0; i < images.size(); i++)
            arr[i] = new File(images.get(i));

        try {
            params.put("images[]", arr);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }


        client.post("http://www.website.com/Ser.php", params, new AsyncHttpResponseHandler() {
            public void onSuccess(int statusCode, cz.msebera.android.httpclient.Header[] headers, byte[] responseBody) {
                try {
                    Log.d("PHPmassage", new String(responseBody, "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onFailure(int statusCode, cz.msebera.android.httpclient.Header[] headers, byte[] responseBody, Throwable error) {
                Toast.makeText(getApplicationContext(), "Upload Failed!",
                        Toast.LENGTH_LONG).show();
            }
        });
    }

PHP代码

<?php
    $Name = $_POST["Name"];
    $dest="Images/" . $Name;

    if(!is_dir($dest))
        mkdir($dest);

    for ($i=0;$i<intval($_POST["Count"]);$i++)
        move_uploaded_file($_FILES['images']["tmp_name"][$i], $dest . "/" . $_FILES['images']["name"][$i]);
?>

0 个答案:

没有答案
相关问题