Skip to content

cURL - Send 2+ files using the same parameter name ("file[]") #15859

Open

Description

@ghnp5

Description

The pull request #8292 made it possible to send an array of parameters of the same name.

However, it doesn't seem to support files:

I'm using PHP 8.3, but I'm not succeeding in doing this:

curl_setopt($ch, CURLOPT_HTTPHEADER, [
	'Content-Type: multipart/form-data'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
	'file' => [
		new CURLFile($file1, posted_filename: 'File1.jpg'),
		new CURLFile($file2, posted_filename: 'File2.jpg')
	]
]);

PHP Fatal error: Uncaught Error: Object of class CURLFile could not be converted to string

Would it be possible to fix this, please?

Thank you very much!

Activity

  1. cmb69 commented on Sep 12, 2024

    @cmb69
    Member

    I think it makes to support this, but in my opinion it's even too late for PHP 8.4.

  2. rbro commented on Jul 25, 2025

    @rbro

    I'm running into this too trying to send files to an API. I'm using the below as a workaround to build the multipart/form-data request on my own:

    https://gist.github.com/yookoala/58d5db5da16c6f404ef169eaf5a50249

  3. QcFe commented on Jul 2, 2026

    @QcFe

    no updates on this? :(

  4. Sjord commented on Jul 17, 2026

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions