Problem uploading PHP files

Asked

Viewed 201 times

3

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

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.

Files are images and do not reach 1mb.

Technical details: PHP version 5.5, Zend Framework 1.12.17

Excerpt from the uploading controller:

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 the 18 photos.

  • 1

    Put the snippet of the code that makes the upload for us to see if there is something strange, not any error? timeout? allocated memory?

  • 1

    also checks the post_max_size and the upload_max_filesize is the limit of each file and the total limit of the post, let’s say it is as 5mb and each file of yours is 1mb, will send only 5 files. It is more or less in this line that works.

  • Is it possible to give a var_dump in $_FILES, before the for, to know if are coming all the files?

1 answer

1


Realize that the array $_FILES["fotos"] has only 5 positions (name, type, tmp_name, error, size)? So only 5 photos are recorded in the bank.

Try to iterate on $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);
        }
    }
}
  • That was it! Thank you. How do I finish or mark the question as resolved? I’m new here hahaha

  • On the left side of the answer, just below the voting system, there is the button with an icon of a "right", just click on it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.