php / php/php-src

http context - allow content to be a stream/resource

Aperta
#19,249 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@ndossche ci sta già lavorando.

Dal 27/7/2025.

  • #19267 di @ndossche — aperta
Category: Streams Feature Status: Verified
Lingua principale
C
Stelle
40.4k
Fork
8.1k
Merge medio
2g 13h
PR unite (30g)
96

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.