]> granicus.if.org Git - php/commitdiff
Fixed bug #48962 (cURL does not upload files with specified filename).
authorIlia Alshanetsky <iliaa@php.net>
Tue, 21 Jul 2009 15:56:08 +0000 (15:56 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 21 Jul 2009 15:56:08 +0000 (15:56 +0000)
NEWS
ext/curl/interface.c

diff --git a/NEWS b/NEWS
index 608f867762d433213f4fbb31467521c3909af516..7b1a7905d240da08307501a2bd8e89fb628e60ea 100644 (file)
--- 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).
index cb1cba2d86861815277c644d8935ef1574140928..791d15b32f658907cd988f6fd73b2d2e33101c95 100644 (file)
@@ -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,