WordPress / WordPress/Requests

Uploading files

Open
#664 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
3.6k
Forks
500
Avg merge
2d 21h
Merged PRs (30d)
5

Description

As I see file uploads are still not possible, even though the fix was suggested some 4 years ago.

Currently I needed to post files and I wasn't in the mood for rewriting stuff in my app, so this is what I came up with:

$hooks = new Requests_Hooks();
$hooks->register('curl.before_send', function ($ch) {
  if (function_exists('curl_file_create')) { // php 5.5+
    $cFile = curl_file_create($_FILES['uploadFile']['tmp_name'], '', $_FILES['uploadFile']['name']);
  } else { // 
    $cFile = '@' . realpath($_FILES['uploadFile']['tmp_name']);
  }
  $_POST['uploadFile'] = $cFile;
  
  curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
});
$resp = Requests::post($url, $headers, [], $options);

Just sharing in case it helps someone.

Close when #313 is ready :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue includes a PHP Requests_Hooks workaround using the curl.before_send hook and refers to #313. Start by reading #313 and the request-handling entry points it identifies. Done means file uploads are supported without requiring callers to modify the request through a custom hook.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.