-2

I got a problem with a multiple upload of images using a form.

The code works to upload 1 image (var_dump of $_POST & $_FILES are ok and completed in action_gallery.php), but it bugs when I want to upload more than 1 file (no more var_dump and got undefined index error for my array pictures[]).

I'm losing all info: no more $_POST, no $_FILES... except that everything goes well when I only got 1 picture. Someone got an idea where is my mistake?

HTML:

<form method="post" action="modele/action_gallery.php" enctype="multipart/form-data">       
    <table id="table_header_diaporama">
        <tr>
            <td align="center" colspan="3">
                <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /><input class="text_profile_form" type="file" name="pictures[]" multiple="multiple" />
                <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /><input class="text_profile_form" type="file" name="pictures[]" multiple="multiple" />
                <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /><input class="text_profile_form" type="file" name="pictures[]" multiple="multiple" />
            </td>
        </tr>
    </table>
</form>

php.ini:

file_uploads = On
max_file_uploads = 20
upload_max_filesize = 100M
post_max_size = 100M

Thanks a lot.

Edit: I managed to recover my $_POST switching enctype="multipart/form-data" by enctype="application/x-www-form-urlencoded". Now, checking the content to see if I got everything ok.

Edit2: making $count = count($_FILES['pictures']['name']); echo '$count: '.$count; gives me 0; so, my problem is still not sorted out! $_POST ok now, but $_FILES is still empty!

Edit3: I finally restored enctype="multipart/form-data" switch off the computer for the night... and it was working afterwards... got no clue why know it works!!! (with 1 or more than 1 input lines to answer to timgavin!).

Mayeshh
  • 9
  • 3
  • I'm not sure you can populate the array that way. see: http://stackoverflow.com/questions/20184670/html-php-form-input-as-array – hoss Jun 12 '15 at 19:51
  • I tried to modify the names of input accordingly, but it doesn't change the fact that nothing goes through when I try to upload 2 pics. Even the $_POST is lost, that what I cannot understand... – Mayeshh Jun 12 '15 at 20:14
  • Did you have a boundary? `boundary=AAABBBXXX` – hoss Jun 12 '15 at 20:44
  • nope, not as far as I know... – Mayeshh Jun 12 '15 at 20:57

1 Answers1

0

I think your multiple form elements with the same names may be overwriting each other.

If you're only selecting images with the first and/or second elements - and since they all have the same names - perhaps the third element may be overwriting the first two with empty values.

Since you're using multiple="multiple", try using only one form element and see what happens.

<form method="post" action="modele/action_gallery.php" enctype="multipart/form-data">       
    <table id="table_header_diaporama">
        <tr>
            <td align="center" colspan="3">
                <input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
                <input class="text_profile_form" type="file" name="pictures[]" multiple="multiple" />
            </td>
        </tr>
    </table>
</form>
timgavin
  • 4,972
  • 4
  • 36
  • 48