Skip to content

Commit d741138

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #46696 (cURL fails in upload files with specified content-type)
1 parent 12e27a7 commit d741138

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

ext/curl/interface.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,17 +1582,37 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
15821582
* must be explicitly cast to long in curl_formadd
15831583
* use since curl needs a long not an int. */
15841584
if (*postval == '@') {
1585+
char *type;
15851586
++postval;
1587+
1588+
if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + strlen(postval)))) {
1589+
*type = '\0';
1590+
}
15861591
/* safe_mode / open_basedir check */
15871592
if (php_check_open_basedir(postval TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(postval, "rb+", CHECKUID_CHECK_MODE_PARAM))) {
1593+
if (type) {
1594+
*type = ';';
1595+
}
15881596
RETVAL_FALSE;
15891597
return 1;
15901598
}
1591-
error = curl_formadd(&first, &last,
1599+
if (type) {
1600+
type++;
1601+
error = curl_formadd(&first, &last,
1602+
CURLFORM_COPYNAME, string_key,
1603+
CURLFORM_NAMELENGTH, (long)string_key_len - 1,
1604+
CURLFORM_FILE, postval,
1605+
CURLFORM_CONTENTTYPE, type,
1606+
CURLFORM_END);
1607+
*(type - 1) = ';';
1608+
} else {
1609+
error = curl_formadd(&first, &last,
15921610
CURLFORM_COPYNAME, string_key,
15931611
CURLFORM_NAMELENGTH, (long)string_key_len - 1,
1594-
CURLFORM_FILE, postval,
1612+
CURLFORM_FILE, postval,
15951613
CURLFORM_END);
1614+
1615+
}
15961616
} else {
15971617
error = curl_formadd(&first, &last,
15981618
CURLFORM_COPYNAME, string_key,

0 commit comments

Comments
 (0)