[wp-trac] [WordPress Trac] #63828: Can't use `CURLFile` with `wp_remote_post`

WordPress Trac noreply at wordpress.org
Thu Aug 14 21:56:01 UTC 2025


#63828: Can't use `CURLFile` with `wp_remote_post`
-------------------------+-----------------------------
 Reporter:  okvee        |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  HTTP API     |    Version:  6.8.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Example code on WordPress plugin:
 {{{#!php
 <?php
 $imageFile = 'image.jpg';
 $postFields = [];

 $Finfo = new finfo();
 $fileMimeType = $Finfo->file($imageFile, FILEINFO_MIME_TYPE);
 unset($Finfo);

 $CurlFile = new CURLFile($imageFile, $fileMimeType, 'curl-upload-' .
 basename($imageFile));
 $postFields['image'] = $CurlFile;
 unset($CurlFile, $fileMimeType);

 $args = [
     'body' => $postFields,
     'sslverify' => false, // for self-signed localhost.
 ];
 wp_remote_post('https://localhost/myupload.php', $args);
 }}}

 And on **myupload.php** file. I use few code to show how it work only.
 {{{#!php
 <?php
 move_uploaded_file($_FILES['image']['tmp_name'], __DIR__.'/new-
 image.jpg');
 $logs = print_r($_POST, true) . PHP_EOL .
     print_r($_FILES, true) . PHP_EOL;
 file_put_content(__DIR__ . '/log.txt', $logs);
 }}}


 The file data will be send as text to destination (myupload.php).

 This is because of these lines in [wp-
 includes/Requests/src/Transport/Curl.php](https://github.com/WordPress
 /wordpress-develop/blob/c726220a21d13fdb5409372b652c9460c59ce1db/src/wp-
 includes/Requests/src/Transport/Curl.php#L387C1-L396C4) inside method
 `setup_handle()` convert POST body to string.
 So, `CURLFile` is dead and not working.

 Compare to native PHP cURL functions. It is working fine.
 {{{#!php
 <?php
 $ch = curl_init('https://localhost/myupload.php');
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_POST, true);
 // disable SSL verify. this is for test with self signed (local host)
 only.
 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);

 $response = curl_exec($ch);
 curl_close($ch);
 }}}

 Please add an option, maybe a hook to skip convert POST data to let
 `CURLFile` works.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63828>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list