iliaa                                    Tue, 21 Jul 2009 15:56:08 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=284546

Log:
Fixed bug #48962 (cURL does not upload files with specified filename).

Bug: http://bugs.php.net/48962 (Assigned) cURL does not upload files with 
specified filename
      
Changed paths:
    U   php/php-src/branches/PHP_5_2/NEWS
    U   php/php-src/branches/PHP_5_2/ext/curl/interface.c
    U   php/php-src/branches/PHP_5_3/NEWS
    U   php/php-src/branches/PHP_5_3/ext/curl/interface.c
    U   php/php-src/trunk/ext/curl/interface.c

Modified: php/php-src/branches/PHP_5_2/NEWS
===================================================================
--- php/php-src/branches/PHP_5_2/NEWS   2009-07-21 14:44:58 UTC (rev 284545)
+++ php/php-src/branches/PHP_5_2/NEWS   2009-07-21 15:56:08 UTC (rev 284546)
@@ -5,6 +5,8 @@
   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).

Modified: php/php-src/branches/PHP_5_2/ext/curl/interface.c
===================================================================
--- php/php-src/branches/PHP_5_2/ext/curl/interface.c   2009-07-21 14:44:58 UTC 
(rev 284545)
+++ php/php-src/branches/PHP_5_2/ext/curl/interface.c   2009-07-21 15:56:08 UTC 
(rev 284546)
@@ -1573,33 +1573,33 @@
                                         * 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,
                                                                                
         CURLFORM_COPYNAME, string_key,

Modified: php/php-src/branches/PHP_5_3/NEWS
===================================================================
--- php/php-src/branches/PHP_5_3/NEWS   2009-07-21 14:44:58 UTC (rev 284545)
+++ php/php-src/branches/PHP_5_3/NEWS   2009-07-21 15:56:08 UTC (rev 284546)
@@ -6,6 +6,8 @@
 - 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

Modified: php/php-src/branches/PHP_5_3/ext/curl/interface.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/curl/interface.c   2009-07-21 14:44:58 UTC 
(rev 284545)
+++ php/php-src/branches/PHP_5_3/ext/curl/interface.c   2009-07-21 15:56:08 UTC 
(rev 284546)
@@ -1800,33 +1800,33 @@
                                         * 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,
                                                                                
         CURLFORM_COPYNAME, string_key,

Modified: php/php-src/trunk/ext/curl/interface.c
===================================================================
--- php/php-src/trunk/ext/curl/interface.c      2009-07-21 14:44:58 UTC (rev 
284545)
+++ php/php-src/trunk/ext/curl/interface.c      2009-07-21 15:56:08 UTC (rev 
284546)
@@ -1863,33 +1863,33 @@
                                         * 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';
+                                               }
                                                /* open_basedir check */
                                                if 
(php_check_open_basedir(postval TSRMLS_CC)) {
                                                        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, key,
-                                                                               
         CURLFORM_NAMELENGTH, l,
-                                                                               
         CURLFORM_FILE, postval,
-                                                                               
         CURLFORM_CONTENTTYPE, type + sizeof(";type=") - 1,
-                                                                               
         CURLFORM_END);
                                                        *type = ';';
-                                               } else {
-                                                       error = 
curl_formadd(&first, &last,
-                                                                               
         CURLFORM_COPYNAME, key,
-                                                                               
         CURLFORM_NAMELENGTH, l,
-                                                                               
         CURLFORM_FILE, postval,
-                                                                               
         CURLFORM_END);
-
                                                }
+                                               if (filename) {
+                                                       *filename = ';';
+                                               }
                                        } else {
                                                error = curl_formadd(&first, 
&last,
                                                                                
         CURLFORM_COPYNAME, key,

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to