]> 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 f83cfcccffd505c84091604be9fd28344d4c1a26..5e29868627b4dd4f4125c63bbe7a98e10d9b9686 100644 (file)
--- 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
index 7ee9b367d2a4eadba936609f6fc46c5e3f114db2..d72f1dfb4d6bfbf6bba3ad6a23c61ced6da30cf0 100644 (file)
@@ -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,