Make WordPress Core

Opened 7 years ago

Last modified 7 years ago

#41608 new defect (bug)

Post files using cURL

Reported by: codealfa's profile codealfa Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.6
Component: HTTP API Keywords:
Focuses: Cc:


It's impossible to post files by http using cURL via the WordPress API.

If you look at the code in the setup_handle method in Requests_Transport_cURL class found in the /wp-includes/Requests/Transport/cURL.php file, you'll see that the POST data is always converted to a string using the PHP http_build_query function. However, according to the PHP manual at, the value passed to CURLOPT_POSTFIELDS must be an array if files are passed to this option.

Change History (4)

#1 @SergeyBiryukov
7 years ago

  • Component changed from General to HTTP API

#2 @codealfa
7 years ago

A possible fix could be to simply add the post value to the CURLOPT_POSTFIELDS option without converting it to a string if the value is an array and the Content-Type header has been given as multipart/form-data. According to the PHP manual, this Content-Type header will be set if the post value is an array.

#3 @ocean90
7 years ago

  • Version changed from 4.8.1 to 4.6

Hello @codealfa, welcome to WordPress Trac!

Thanks for your report. Please note that Requests is an external library, so this issue should also be reported on the GitHub repo at


#4 @codealfa
7 years ago

Ok thanks for the info. I've done that at

Note: See TracTickets for help on using tickets.