@@ -119,6 +119,8 @@ public function __toString() : string
119119 }
120120
121121 /**
122+ * NOTE: Created by comparing a request made with Firefox.
123+ *
122124 * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#multipartform-data
123125 *
124126 * @return string
@@ -144,22 +146,30 @@ protected function getMultipartBody() : string
144146 $ files = ArraySimple::convert ($ this ->getFiles ());
145147 foreach ($ files as $ field => $ file ) {
146148 $ field = \htmlspecialchars ($ field , \ENT_QUOTES | \ENT_HTML5 );
147- $ filename = \htmlspecialchars ($ file ->getName (), \ENT_QUOTES | \ENT_HTML5 );
149+ $ field = \preg_replace ('/\[\d+]/ ' , '[] ' , $ field );
150+ $ filename = \htmlspecialchars ($ file ->getFullPath (), \ENT_QUOTES | \ENT_HTML5 );
151+ $ contentType = $ file ->getClientType () ?: 'application/octet-stream ' ;
148152 $ getContentsOf = $ file ->isMoved () ? $ file ->getDestination () : $ file ->getTmpName ();
149153 $ data = '' ;
150154 if ($ getContentsOf !== '' ) {
151155 $ data = \file_get_contents ($ getContentsOf );
152156 }
153157 $ bodyParts [] = \implode ("\r\n" , [
154158 "Content-Disposition: form-data; name= \"{$ field }\"; filename= \"{$ filename }\"" ,
155- 'Content-Type: ' . $ file -> getClientType () ,
159+ 'Content-Type: ' . $ contentType ,
156160 '' ,
157161 $ data ,
158162 ]);
159163 }
160- $ boundary = \explode ('; ' , $ this ->getContentType (), 2 );
161- $ boundary = \trim ($ boundary [1 ]);
162- $ boundary = \substr ($ boundary , \strlen ('boundary= ' ));
164+ $ boundary = '' ;
165+ $ boundaryParts = \explode ('; ' , $ this ->getContentType ());
166+ foreach ($ boundaryParts as $ boundaryPart ) {
167+ $ boundaryPart = \trim ($ boundaryPart );
168+ if (\str_starts_with (\strtolower ($ boundaryPart ), 'boundary= ' )) {
169+ $ boundary = \substr ($ boundaryPart , \strlen ('boundary= ' ));
170+ break ;
171+ }
172+ }
163173 foreach ($ bodyParts as &$ part ) {
164174 $ part = "-- {$ boundary }\r\n{$ part }" ;
165175 }
@@ -175,6 +185,7 @@ protected function getMultipartBody() : string
175185 /*
176186 $serverLength = (string) $_SERVER['CONTENT_LENGTH'];
177187 $algoLength = (string) \strlen($bodyParts);
188+ \var_dump($serverLength, $algoLength);
178189 if ($serverLength !== $algoLength) {
179190 throw new \Exception(
180191 '$_SERVER CONTENT_LENGTH is ' . $serverLength
0 commit comments