cURL - Send 2+ files using the same parameter name ("file[]")
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 40.4k
- Forks
- 8.1k
- Avg merge
- 2d 13h
- Merged PRs (30d)
- 96
Description
Description
The pull request https://github.com/php/php-src/pull/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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the PHP cURL handling for CURLOPT_POSTFIELDS, CURLFile values, and multipart/form-data arrays, using the reproduction in the issue and the earlier array-parameter change in pull request 8292 as entry points. Verify the behavior with two CURLFile objects under one field name; done means both files are encoded and sent without the object-conversion fatal error, with regression coverage added.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, php
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 58/100