Skip to content
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
Merged

Handle nested uploaded files correctly #1812

merged 2 commits into from
Mar 10, 2016

Conversation

akrabat
Copy link
Member

@akrabat 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

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
Copy link

👍 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
Copy link
Contributor

👍

codeguy added a commit that referenced this pull request Mar 10, 2016
@codeguy codeguy merged commit bfc3543 into slimphp:3.x Mar 10, 2016
@akrabat akrabat changed the title Nested uploaded files Handle nested uploaded files correctly Mar 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants