php / php/php-src

http context - allow content to be a stream/resource

Open
#19,249 1 comment 0 reactions 1 assignee View on GitHub

@ndossche is already working on this.

Since Jul 27, 2025.

  • #19267 by @ndossche — open
Category: Streams Feature Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

I am using file_get_contents with a HTTP context to POST a large request to a URL (https://www.php.net/manual/en/context.http.php). I noticed that the content field has to be a string:

<?php
$post_data = file_get_contents('data_to_send.txt');

file_get_contents('https://test.com/test.php', false, stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header'  => array(
        	'Content-type: multipart/form-data',
        ),
        'content' => $post_data,
    )
)));
?>

Would it be possible to allow content to be a stream/resource so that I don't have to read in the file contents first? This would be similar to CURLOPT_INFILE which accepts a file handle resource like fopen.

The reason I'm trying to send data this way and not with curl is because of #15859. I'm trying to build my own multipart/form-data request per my comment there, as I'm connecting to an API that needs multiple files with the same name.

Thanks for your help.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.