Problem uploading files in PHP

Question:

Hi, I have a problem uploading files from my system. When placing more than 5 files in the "input multiple file" field, only 5 are recorded in the database, that is, if I put 18 files, only 5 files will be recorded.

The strange thing is that in the php.ini file the "max_file_uploads" is with the value 20, the "post_max_size" and the "upload_max_filesize" are with 64M.

The files are images and do not reach 1mb.

Technical details: PHP version 5.5, Zend Framework 1.12.17

Excerpt from the controller that uploads:

if (isset($_FILES ['fotos'])) {
    $fotos = $_FILES ['fotos'];
    //Inserção de multiplas imagens
    for($i = 0; $i < count($fotos); $i++) {
        //Inserção normal da imagem
        if (!empty($fotos ['name'][$i])) {
            $data_fotos = array();
            $data_fotos ['type'] = $fotos ['type'][$i];
            $data_fotos ['tmp_name'] = $fotos ['tmp_name'][$i];
            $ite->inserirFoto($codalb, $codusu, $data_fotos);
        }
    }
}

I gave a "print_r($_files["photos"])" in the controller, below is the value of the array:

[name] => Array
    (
        [0] => 01 - Copia (2).jpg
        [1] => 01 - Copia.jpg
        [2] => 01.jpg
        [3] => 02 - Copia (2).jpg
        [4] => 02 - Copia.jpg
        [5] => 02.jpg
        [6] => 03 - Copia (2).jpg
        [7] => 03 - Copia.jpg
        [8] => 03.jpg
        [9] => 05 - Copia (2).jpg
        [10] => 05 - Copia.jpg
        [11] => 05.jpg
        [12] => 06 - Copia (2).jpg
        [13] => 06 - Copia.jpg
        [14] => 06.jpg
        [15] => 07 - Copia (2).jpg
        [16] => 07 - Copia.jpg
        [17] => 07.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
        [10] => image/jpeg
        [11] => image/jpeg
        [12] => image/jpeg
        [13] => image/jpeg
        [14] => image/jpeg
        [15] => image/jpeg
        [16] => image/jpeg
        [17] => image/jpeg
    )

[tmp_name] => Array
    (
        [0] => /tmp/phpfcCVZ1
        [1] => /tmp/phpXCYDdx
        [2] => /tmp/phpiLuvr2
        [3] => /tmp/phpFncCFx
        [4] => /tmp/php1KEYT2
        [5] => /tmp/phpQ8Fy8x
        [6] => /tmp/php3eRkn3
        [7] => /tmp/phpCGkqCy
        [8] => /tmp/php3fxNR3
        [9] => /tmp/phpZpvu7y
        [10] => /tmp/phpk6Dpn4
        [11] => /tmp/php5JhxDz
        [12] => /tmp/phpIGZTT4
        [13] => /tmp/php9gVwaA
        [14] => /tmp/phptxyor5
        [15] => /tmp/phpZmPtIA
        [16] => /tmp/php8LTHZ5
        [17] => /tmp/phpXna8gB
    )

[error] => Array
    (
        [0] => 0
        [1] => 0
        [2] => 0
        [3] => 0
        [4] => 0
        [5] => 0
        [6] => 0
        [7] => 0
        [8] => 0
        [9] => 0
        [10] => 0
        [11] => 0
        [12] => 0
        [13] => 0
        [14] => 0
        [15] => 0
        [16] => 0
        [17] => 0
    )

[size] => Array
    (
        [0] => 186806
        [1] => 186806
        [2] => 186806
        [3] => 192111
        [4] => 192111
        [5] => 192111
        [6] => 277800
        [7] => 277800
        [8] => 277800
        [9] => 220789
        [10] => 220789
        [11] => 220789
        [12] => 265068
        [13] => 265068
        [14] => 265068
        [15] => 175393
        [16] => 175393
        [17] => 175393
    )

As you can see it comes with 18 photos.

Answer:

Do you notice that the $_FILES["fotos"] array has only 5 positions ( name , type , tmp_name , error , size )? That's why only 5 photos are recorded in the bank.

Try iterating over $fotos["name"] , for example:

if (isset($_FILES ['fotos']))
{
    $fotos = $_FILES ['fotos'];

    // --------------------------vvvvvvvv
    for($i = 0; $i < count($fotos["name"]); $i++)
    {
        if (!empty($fotos ['name'][$i])) 
        {
            $data_fotos = array();
            $data_fotos ['type'] = $fotos ['type'][$i];
            $data_fotos ['tmp_name'] = $fotos ['tmp_name'][$i];
            $ite->inserirFoto($codalb, $codusu, $data_fotos);
        }
    }
}
Scroll to Top