Skip to content

ext/curl: post multiple similarly-named files with curl - #22740

Open
Sjord wants to merge 4 commits into
php:masterfrom
Sjord:curl-post-multi-file
Open

Sjord wants to merge 4 commits into
php:masterfrom
Sjord:curl-post-multi-file

Conversation

@Sjord

@Sjord Sjord commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Make it possible to post multiple files with the same name using cURL.
It was already possible to post files, and it was possible to post
multiple strings with the same name. This moves things around to combine
these two features.

Closes php#15859
@Sjord
Sjord force-pushed the curl-post-multi-file branch from c8f8de7 to aece997 Compare July 15, 2026 12:44
@Sjord
Sjord marked this pull request as ready for review July 15, 2026 12:58
@Sjord
Sjord requested a review from adoy as a code owner July 15, 2026 12:58
@Sjord

Sjord commented Jul 27, 2026

Copy link
Copy Markdown
Contributor Author

@derickr Could you take a look at this? When you made #8292, was there a reason that it didn't work for files, or was this incidental?

@Sjord Sjord changed the title Post multiple similarly-named files with curl ext/curl: post multiple similarly-named files with curl Jul 30, 2026
@Sjord

Sjord commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

@cmb69 could you perhaps review this please?

@Girgias Girgias left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing part of the refactoring with the behavioural changes makes it hard to follow along.

Could you maybe first split build_mime_structure_from_hash into multiple functions dealing with the different types in a different PR, and then rebase this PR when that one landed?

@Sjord

Sjord commented Aug 8, 2026

Copy link
Copy Markdown
Contributor Author

I agree that the changes view of this PR is a mess. I moved the inner loop from build_mime_structure_from_hash to its own function. There are hardly any other changes. Splitting this up into multilple pull requests is not going to make things clearer, I'm afraid.

Could you take a look at this PR with white-space changes ignored? I think that makes it easier to see what's going on.

@Sjord
Sjord requested a review from Girgias August 11, 2026 09:20
@Sjord

Sjord commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

@Girgias could you take another look at this?

@Sjord

Sjord commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@arnaud-lb Could you take a look at this?

Comment thread ext/curl/interface.c

if (error != CURLE_OK) {
zend_string_release_ex(string_key, 0);
goto out_mime;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, error was eventually passed to SAVE_CURL_ERROR(ch, error), but now we skip over it.

Comment thread ext/curl/interface.c Outdated
}
} ZEND_HASH_FOREACH_END();

SAVE_CURL_ERROR(ch, error);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now unreachable (except for error = CURLE_OK)

Comment thread ext/curl/interface.c Outdated
}

postval = Z_STR_P(prop);
return add_simple_field(mime, string_key, current);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Inconsistent indentation on this line (spaces vs tabs)

Comment thread ext/curl/interface.c Outdated
static inline zend_result build_mime_structure_from_hash(php_curl *ch, zval *zpostfields) /* {{{ */
{
HashTable *postfields = Z_ARRVAL_P(zpostfields);
static inline CURLcode add_form_field(php_curl *ch, curl_mime *mime, zend_string *string_key, zval *current, zval *zpostfields) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please add a newline before {

CURLOPT_POSTFIELDS with nested arrays
--EXTENSIONS--
curl
sockets

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sockets is not used in this test

echo "TypeError: {$e->getMessage()}\n";
}
?>
--EXPECTF--

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can be --EXPECT-- (without F)

sockets
--FILE--
<?php
$socket = stream_socket_server("tcp://0.0.0.0:29999", $errno, $errstr);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Please use port 0 + stream_socket_get_name() as in

$server3 = stream_socket_server("tcp://127.0.0.1:0", $errno, $errstr,

@Sjord
Sjord force-pushed the curl-post-multi-file branch from f01e914 to 6ffa446 Compare October 12, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants