Skip to content

Psr17Factory::buildServerRequestFromGlobals() throws TypeError when encountering nested array of file uploads #226

@mfb

Description

@mfb

PHP version: 8.2.5

Description

PHP allows file uploads to be nested in an arbitrarily deep array structure (see example markup below). For requests using this feature, Psr17Factory::buildServerRequestFromGlobals() throws TypeError: Http\Discovery\Psr17Factory::createStreamFromFile(): Argument ($filename) must be of type string, array given, called in /vendor/php-http/discovery/src/Psr17Factory.php on line 271 in Http\Discovery\Psr17Factory->createStreamFromFile() (line 120 of /vendor/php-http/discovery/src/Psr17Factory.php)

How to reproduce
Uploading a file to this script should throw the TypeError:

<pre>
<form method="post" enctype="multipart/form-data">
  <input multiple="multiple" type="file" name="files[upload_0][]">
  <input type="submit" name="submit">
</form>

<?php
use Http\Discovery\Psr17Factory;
require './vendor/autoload.php';
print_r($_FILES);
(new Psr17Factory())->createServerRequestFromGlobals();

Possible Solution

Additional context
Discovered in getsentry/sentry-php#1517

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions