Search code examples
phphtmlmultiple-file-upload

Multiple image upload error when uploading more than 20 images or so


I have a problem with multiple uploads on multiple fields.I have 3 file upload fields.when I upload ten in each. I am not getting some files.

HTML Code

<input type="file" name="before[]" multiple>
<input type="file" name="during[]" multiple>
<input type="file" name="after[]" multiple>

when I print_r($_FILES); I get like the following output

Array
(
    [before] => Array
        (
            [name] => Array
              (
                [0] => loose_diamond.jpg
                [1] => silver.jpg
                [2] => loose_diamond.jpg
                [3] => silver_ware.jpg
                [4] => diamond.jpg
                [5] => loose_diamond.jpg
                [6] => diamond.jpg
                [7] => loose_diamond.jpg
                [8] => diamond.jpg
                [9] => loose_diamond.jpg
              )

        [type] => Array
            (
                [0] => image/jpeg
                [1] => image/jpeg
                [2] => image/jpeg
                [3] => image/jpeg
                [4] => image/jpeg
                [5] => image/jpeg
                [6] => image/jpeg
                [7] => image/jpeg
                [8] => image/jpeg
                [9] => image/jpeg
            )

        [tmp_name] => Array
            (
                [0] => /tmp/phpr1CABT
                [1] => /tmp/phpEhK0Wk
                [2] => /tmp/phpVq54jM
                [3] => /tmp/phpan3pId
                [4] => /tmp/phplXVb0G
                [5] => /tmp/phpWWfyja
                [6] => /tmp/php5zLcZD
                [7] => /tmp/phpWZu4F7
                [8] => /tmp/phpHk8VzB
                [9] => /tmp/php4OQPI5
            )

        [error] => Array
            (
                [0] => 0
                [1] => 0
                [2] => 0
                [3] => 0
                [4] => 0
                [5] => 0
                [6] => 0
                [7] => 0
                [8] => 0
                [9] => 0
            )

        [size] => Array
            (
                [0] => 6450
                [1] => 6851
                [2] => 6450
                [3] => 7866
                [4] => 6372
                [5] => 6450
                [6] => 6372
                [7] => 6450
                [8] => 6372
                [9] => 6450
            )

    )

[during] => Array
    (
        [name] => Array
            (
                [0] => loose_diamond.jpg
                [1] => silver.jpg
                [2] => silver.jpg
                [3] => silver_ware.jpg
                [4] => silver_ware.jpg
                [5] => watch.jpg
                [6] => machinery.jpg
                [7] => conis.jpg
                [8] => silver_ware.jpg
                [9] => machinery.jpg
            )

        [type] => Array
            (
                [0] => image/jpeg
                [1] => image/jpeg
                [2] => image/jpeg
                [3] => image/jpeg
                [4] => image/jpeg
                [5] => image/jpeg
                [6] => image/jpeg
                [7] => image/jpeg
                [8] => image/jpeg
                [9] => image/jpeg
            )

        [tmp_name] => Array
            (
                [0] => /tmp/php3eBKVz
                [1] => /tmp/phpk0GxK4
                [2] => /tmp/phplPxWDz
                [3] => /tmp/php2J8Ry4
                [4] => /tmp/php5b8pwA
                [5] => /tmp/phpU1UvZ6
                [6] => /tmp/phpHP7zAD
                [7] => /tmp/phpKpfZwa
                [8] => /tmp/phpl9SHvH
                [9] => /tmp/php693Gbf
            )

        [error] => Array
            (
                [0] => 0
                [1] => 0
                [2] => 0
                [3] => 0
                [4] => 0
                [5] => 0
                [6] => 0
                [7] => 0
                [8] => 0
                [9] => 0
            )

        [size] => Array
            (
                [0] => 6450
                [1] => 6851
                [2] => 6851
                [3] => 7866
                [4] => 7866
                [5] => 8119
                [6] => 8173
                [7] => 8789
                [8] => 7866
                [9] => 8173
            )

    )

[images[]] => Array
    (
        [name] => machinery.jpg
        [type] => image/jpeg
        [tmp_name] => /tmp/php693Gbf
        [error] => 0
        [size] => 8173
    )

)

Note: when I upload 5 images each it works fine.


Solution

  • You need to set the value of upload_max_filesize and post_max_size in your php.ini :

    ; Maximum allowed size for uploaded files.
    upload_max_filesize = 2048M //or as per your requirements
    
    ; Must be greater than or equal to upload_max_filesize
    post_max_size = 2048M  //or as per your requirements
    

    After modifying php.ini file(s), you need to restart your HTTP server to use new configuration.

    Read this : http://php.net/manual/en/ini.core.php