protected function buildBody() {
		
		// If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads
		// will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off
		// and use CurlFile.

		if (count($this->files())) {
			$body = [];
			foreach ($this->params as $key => $value) {
				$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"", "", $value]);
			}
			foreach ($this->files as $key => $path) {
				$file = new File($path);
				$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file->name()}\"", "Content-Type: application/octet-stream", "", $file->contents()]);
			}

			do {
				$boundary = "---------------------" . md5(mt_rand() . microtime());
			} while (preg_grep("/{$boundary}/", $body));
			foreach ($body as $i => $part) {
				$body[$i] = "--{$boundary}\r\n" . $part;
			}
			$body[] = "--{$boundary}--";
			$body[] = "";

			curl_setopt($this->curl, CURLOPT_POSTFIELDS, implode("\r\n", $body));
			$this->header('Content-Type', 'multipart/form-data; boundary=' . $boundary);
		} else {
			curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($this->params));
			$this->header('Content-Type', 'application/x-www-form-urlencoded');
		}
	}
protected function buildBody() {
		
		// If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads
		// will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off
		// and use CurlFile.

		if (count($this->files())) {
			$body = [];
			foreach ($this->params as $key => $value) {
				$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"", "", $value]);
			}
			foreach ($this->files as $key => $path) {
				$file = new File($path);
				$body[] = implode("\r\n", ["Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file->name()}\"", "Content-Type: application/octet-stream", "", $file->contents()]);
			}

			do {
				$boundary = "---------------------" . md5(mt_rand() . microtime());
			} while (preg_grep("/{$boundary}/", $body));
			foreach ($body as $i => $part) {
				$body[$i] = "--{$boundary}\r\n" . $part;
			}
			$body[] = "--{$boundary}--";
			$body[] = "";

			curl_setopt($this->curl, CURLOPT_POSTFIELDS, implode("\r\n", $body));
			$this->header('Content-Type', 'multipart/form-data; boundary=' . $boundary);
		} else {
			curl_setopt($this->curl, CURLOPT_POSTFIELDS, http_build_query($this->params));
			$this->header('Content-Type', 'application/x-www-form-urlencoded');
		}
	}
protected function buildBody ( ) { // If we are uploading files, we have to build the request body manually since the stupid syntax for file uploads // will break non-file values beginning with '@'. When we no longer support PHP 5.4 we can just turn this syntax off // and use CurlFile. if ( count ( $ this -> files ( ) ) ) { $ body = [ ] ; foreach ( $ this -> params as $ key => $ value ) { $ body [ ] = implode ( "\r\n" , [ "Content-Disposition: form-data; name=\"{$key}\"" , "" , $ value ] ) ; } foreach ( $ this -> files as $ key => $ path ) { $ file = new File ( $ path ) ; $ body [ ] = implode ( "\r\n" , [ "Content-Disposition: form-data; name=\"{$key}\"; filename=\"{$file->name()}\"" , "Content-Type: application/octet-stream" , "" , $ file -> contents ( ) ] ) ; } do { $ boundary = "---------------------" . md5 ( mt_rand ( ) . microtime ( ) ) ; } while ( preg_grep ( "/{$boundary}/" , $ body ) ) ; foreach ( $ body as $ i => $ part ) { $ body [ $ i ] = "--{$boundary}\r\n" . $ part ; } $ body [ ] = "--{$boundary}--" ; $ body [ ] = "" ; curl_setopt ( $ this -> curl , CURLOPT_POSTFIELDS , implode ( "\r\n" , $ body ) ) ; $ this -> header ( 'Content-Type' , 'multipart/form-data; boundary=' . $ boundary ) ; } else { curl_setopt ( $ this -> curl , CURLOPT_POSTFIELDS , http_build_query ( $ this -> params ) ) ; $ this -> header ( 'Content-Type' , 'application/x-www-form-urlencoded' ) ; } }
Build the request body.
Build the request body .