php / php/php-src

http context - allow content to be a stream/resource

未关闭
#19,249 1 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

@ndossche 已经在做这个了。

开始于 2025年7月27日。

  • #19267 来自 @ndossche —— 未关闭
Category: Streams Feature Status: Verified
主要语言
C
星标
40.4k
派生
8.1k
平均合并
2 天 13 小时
30 天内合并 PR
96

描述

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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。