From 160c88cfa14df49b763b841c943c321b5ca175f8 Mon Sep 17 00:00:00 2001 From: Ilia Alshanetsky Date: Tue, 21 Jul 2009 15:56:08 +0000 Subject: [PATCH] Fixed bug #48962 (cURL does not upload files with specified filename). --- NEWS | 2 ++ ext/curl/interface.c | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/NEWS b/NEWS index f83cfcccff..5e29868627 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,8 @@ PHP NEWS - Fixed open_basedir circumvention for mail.log. (Maksymilian Arciemowicz, Stas) +- 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 #48899 (is_callable returns true even if method does not exist in diff --git a/ext/curl/interface.c b/ext/curl/interface.c index 7ee9b367d2..d72f1dfb4d 100644 --- a/ext/curl/interface.c +++ b/ext/curl/interface.c @@ -1800,32 +1800,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, -- 2.40.0