@@ -1983,6 +1983,10 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
1983
1983
char * type = NULL , * filename = NULL ;
1984
1984
#if LIBCURL_VERSION_NUM >= 0x073800 /* 7.56.0 */
1985
1985
struct mime_data_cb_arg * cb_arg ;
1986
+ php_stream * stream ;
1987
+ php_stream_statbuf ssb ;
1988
+ size_t filesize = -1 ;
1989
+ curl_seek_callback seekfunc = seek_cb ;
1986
1990
#endif
1987
1991
1988
1992
prop = zend_read_property (curl_CURLFile_class , current , "name" , sizeof ("name" )- 1 , 0 , & rv );
@@ -2008,17 +2012,25 @@ static inline int build_mime_structure_from_hash(php_curl *ch, zval *zpostfields
2008
2012
zval_ptr_dtor (& ch -> postfields );
2009
2013
ZVAL_COPY (& ch -> postfields , zpostfields );
2010
2014
2015
+ if ((stream = php_stream_open_wrapper (ZSTR_VAL (postval ), "rb" , STREAM_MUST_SEEK , NULL ))) {
2016
+ if (!stream -> readfilters .head && !php_stream_stat (stream , & ssb )) {
2017
+ filesize = ssb .sb .st_size ;
2018
+ }
2019
+ } else {
2020
+ seekfunc = NULL ;
2021
+ }
2022
+
2011
2023
cb_arg = emalloc (sizeof * cb_arg );
2012
2024
cb_arg -> filename = zend_string_copy (postval );
2013
- cb_arg -> stream = NULL ;
2025
+ cb_arg -> stream = stream ;
2014
2026
2015
2027
part = curl_mime_addpart (mime );
2016
2028
if (part == NULL ) {
2017
2029
zend_string_release_ex (string_key , 0 );
2018
2030
return FAILURE ;
2019
2031
}
2020
2032
if ((form_error = curl_mime_name (part , ZSTR_VAL (string_key ))) != CURLE_OK
2021
- || (form_error = curl_mime_data_cb (part , -1 , read_cb , seek_cb , free_cb , cb_arg )) != CURLE_OK
2033
+ || (form_error = curl_mime_data_cb (part , filesize , read_cb , seekfunc , free_cb , cb_arg )) != CURLE_OK
2022
2034
|| (form_error = curl_mime_filename (part , filename ? filename : ZSTR_VAL (postval ))) != CURLE_OK
2023
2035
|| (form_error = curl_mime_type (part , type ? type : "application/octet-stream" )) != CURLE_OK ) {
2024
2036
error = form_error ;
0 commit comments