From: Ilia Alshanetsky Date: Tue, 21 Jul 2009 15:56:08 +0000 (+0000) Subject: Fixed bug #48962 (cURL does not upload files with specified filename). X-Git-Tag: php-5.2.11RC1~126 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3050decf1e547fa3527414973c7e28a3e9324e42;p=php Fixed bug #48962 (cURL does not upload files with specified filename). --- diff --git a/NEWS b/NEWS index 608f867762..7b1a7905d2 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS defined as a file handle. (Ilia) - Fixed bug #48980 (Crash when compiling with pdo_firebird). (Felipe) +- Fixed bug #48962 (cURL does not upload files with specified filename). + (Ilia) - Fixed bug #48929 (Double \r\n after HTTP headers when "header" context option is an array). (David Zülke) - Fixed bug #48913 (Too long error code strings in pdo_odbc driver). diff --git a/ext/curl/interface.c b/ext/curl/interface.c index cb1cba2d86..791d15b32f 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1573,32 +1573,32 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu * must be explicitly cast to long in curl_formadd * use since curl needs a long not an int. */ if (*postval == '@') { - char *type; + char *type, *filename; ++postval; if ((type = php_memnstr(postval, ";type=", sizeof(";type=") - 1, postval + Z_STRLEN_PP(current)))) { *type = '\0'; } + if ((filename = php_memnstr(postval, ";filename=", sizeof(";filename=") - 1, postval + Z_STRLEN_PP(current)))) { + *filename = '\0'; + } /* safe_mode / open_basedir check */ if (php_check_open_basedir(postval TSRMLS_CC) || (PG(safe_mode) && !php_checkuid(postval, "rb+", CHECKUID_CHECK_MODE_PARAM))) { RETVAL_FALSE; return 1; } + error = curl_formadd(&first, &last, + CURLFORM_COPYNAME, string_key, + CURLFORM_NAMELENGTH, (long)string_key_len - 1, + CURLFORM_FILENAME, filename ? filename : postval, + CURLFORM_CONTENTTYPE, type ? type + sizeof(";type=") - 1 : "application/octet-stream", + CURLFORM_FILE, postval, + CURLFORM_END); if (type) { - error = curl_formadd(&first, &last, - CURLFORM_COPYNAME, string_key, - CURLFORM_NAMELENGTH, (long)string_key_len - 1, - CURLFORM_FILE, postval, - CURLFORM_CONTENTTYPE, type + sizeof(";type=") - 1, - CURLFORM_END); *type = ';'; - } else { - error = curl_formadd(&first, &last, - CURLFORM_COPYNAME, string_key, - CURLFORM_NAMELENGTH, (long)string_key_len - 1, - CURLFORM_FILE, postval, - CURLFORM_END); - + } + if (filename) { + *filename = ';'; } } else { error = curl_formadd(&first, &last,