@@ -736,29 +736,31 @@ protected function _buildMultipart($method, $params)
736
736
737
737
// check for filenames
738
738
if (in_array ($ key , $ possible_files )) {
739
- $ multipart_request .=
740
- "\r\nContent-Transfer-Encoding: base64 " ;
741
-
742
739
if (// is it a file, a readable one?
743
740
@file_exists ($ value )
744
741
&& @is_readable ($ value )
745
742
746
743
// is it a valid image?
747
- && $ data = @getimagesize ($ params [$ possible_file ])
748
-
749
- // is it a supported image format?
750
8000
- && in_array ($ data [2 ], $ this ->_supported_media_files )
744
+ && $ data = @getimagesize ($ value )
751
745
) {
752
- // try to read the file
753
- ob_start ();
754
- readfile ($ value );
755
- $ data = ob_get_contents ();
756
- ob_end_clean ();
757
- if (strlen ($ data ) == 0 ) {
758
- continue ;
746
+ if (// is it a supported image format?
747
+ in_array ($ data [2 ], $ this ->_supported_media_files )
748
+ ) {
749
+ // try to read the file
750
+ ob_start ();
751
+ readfile ($ value );
752
+ $ data = ob_get_contents ();
753
+ ob_end_clean ();
754
+ if (strlen ($ data ) == 0 ) {
755
+ continue ;
756
+ }
757
+ $ value = $ data ;
759
758
}
760
- $ value = $ data ;
761
759
}
760
+
761
+ $ multipart_request .=
762
+ "\r\nContent-Transfer-Encoding: base64 " ;
763
+ $ value = base64_encode ($ value );
762
764
}
763
765
764
766
$ multipart_request .=
@@ -823,7 +825,7 @@ protected function _callApi($httpmethod, $method, $method_template, $params = ar
823
825
$ authorization = $ this ->_sign ($ httpmethod , $ url , $ params );
824
826
$ params = http_build_query ($ params );
825
827
}
826
- $ ch = curl_init ($ url );
828
+ $ ch = curl_init ($ url );
827
829
curl_setopt ($ ch , CURLOPT_POST , 1 );
828
830
curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ params );
829
831
}
@@ -845,15 +847,16 @@ protected function _callApi($httpmethod, $method, $method_template, $params = ar
845
847
if ($ multipart ) {
846
848
$ first_newline = strpos ($ params , "\r\n" );
847
849
$ multipart_boundary = substr ($ params , 2 , $ first_newline );
848
- $ request_headers [] = 'Content-Type: multipart/form-data; boundary= '
850
+ $ request_headers [] = 'Content-Type: multipart/form-data; boundary= '
849
851
. $ multipart_boundary ;
850
852
}
851
- print_r ( $ request_headers ); die ();
853
+
852
854
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , 1 );
853
855
curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , 0 );
854
856
curl_setopt ($ ch , CURLOPT_HEADER , 1 );
855
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYHOST , 0 );
856
- curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , 0 );
857
+ // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
858
+ // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
859
+ // curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
857
860
curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ request_headers );
858
861
859
862
$ reply = curl_exec ($ ch );
@@ -879,7 +882,19 @@ protected function _parseApiReply($method, $reply)
879
882
{
880
883
// split headers and body
881
884
$ headers = array ();
882
- $ reply = explode ("\r\n\r\n" , $ reply , 2 );
885
+ $ reply = explode ("\r\n\r\n" , $ reply , 4 );
886
+
887
+ // check if using proxy
888
+ if (substr ($ reply [0 ], 0 , 35 ) === 'HTTP/1.1 200 Connection Established ' ) {
889
+ array_shift ($ reply );
890
+ } elseif (count ($ reply ) > 2 ) {
891
+ $ headers = array_shift ($ reply );
892
+ $ reply = array (
893
+ $ headers ,
894
+ implode ("\r\n" , $ reply )
895
+ );
896
+ }
897
+
883
898
$ headers_array = explode ("\r\n" , $ reply [0 ]);
884
899
foreach ($ headers_array as $ header ) {
885
900
$ header_array = explode (': ' , $ header , 2 );
0 commit comments