New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle nested uploaded files correctly #1812

Merged
merged 2 commits into from Mar 10, 2016

Conversation

Projects
None yet
5 participants
@akrabat
Member

akrabat commented Mar 10, 2016

The $_FILES array is very weird when you have a nested name of the type:
<input name="files[details][avatar][]" type="file"> has the structure
is:

    [
        'files' => [
            'tmp_name' => [
                'details' => [
                    'avatar' => [
                        0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
                        1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
                    ],
                ],
            ],
            'name' => [
                'details' => [
                    'avatar' => [
                        0 => 'file0.txt',
                        1 => 'file1.html',
                    ],
                ],
            ],
            'type' => [
                'details' => [
                    'avatar' => [
                        0 => 'text/plain',
                        1 => 'text/html',
                    ],
                ],
            ],
            'error' => [
                'details' => [
                    'avatar' => [
                        0 => 0,
                        1 => 0
                    ],
                ],
            ],
            'size' => [
                'details' => [
                    'avatar' => [
                        0 => 0,
                        1 => 0
                    ],
                ],
            ],
        ],
    ],

As such, when we iterate over the array, we have to normalise each time to ensure that keep the actual $_FILES array key names known all the way down to the actual data.

Fixes #1806

akrabat added some commits Mar 10, 2016

Normalise sub arrays in $_FILES within parseUploadedFiles()
The $_FILES array is very weird when you have a nested name of the type:
<input name="files[details][avatar][]" type="file"> has the structure
is:
```
    [
        'files' => [
            'tmp_name' => [
                'details' => [
                    'avatar' => [
                        0 => __DIR__ . DIRECTORY_SEPARATOR . 'file0.txt',
                        1 => __DIR__ . DIRECTORY_SEPARATOR . 'file1.html',
                    ],
                ],
            ],
            'name' => [
                'details' => [
                    'avatar' => [
                        0 => 'file0.txt',
                        1 => 'file1.html',
                    ],
                ],
            ],
            'type' => [
                'details' => [
                    'avatar' => [
                        0 => 'text/plain',
                        1 => 'text/html',
                    ],
                ],
            ],
            'error' => [
                'details' => [
                    'avatar' => [
                        0 => 0,
                        1 => 0
                    ],
                ],
            ],
            'size' => [
                'details' => [
                    'avatar' => [
                        0 => 0,
                        1 => 0
                    ],
                ],
            ],
        ],
    ],
```

As such, when we iterate over the array, we have to normalise each time
to ensure that keep the actual $_FILES array key names known all the
way down to the actual data.

Fixes #1806

@akrabat akrabat added this to the 3.2.3 milestone Mar 10, 2016

@weierophinney

This comment has been minimized.

Show comment
Hide comment
@weierophinney

weierophinney Mar 10, 2016

👍 This is the whole reason for the UploadedFileInterface. Of course, now we have to go and do errata to PSR-7, as evidently we documented the actual structure PHP does incorrectly.

weierophinney commented Mar 10, 2016

👍 This is the whole reason for the UploadedFileInterface. Of course, now we have to go and do errata to PSR-7, as evidently we documented the actual structure PHP does incorrectly.

@mathmarques

This comment has been minimized.

Show comment
Hide comment
@mathmarques

mathmarques Mar 10, 2016

Contributor

👍

Contributor

mathmarques commented Mar 10, 2016

👍

codeguy added a commit that referenced this pull request Mar 10, 2016

@codeguy codeguy merged commit bfc3543 into slimphp:3.x Mar 10, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@akrabat akrabat changed the title from Nested uploaded files to Handle nested uploaded files correctly Mar 10, 2016

@rrylee

This comment has been minimized.

Show comment
Hide comment
@rrylee

rrylee commented on 60b7926 Mar 11, 2016

nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment