Skip to content

Commit 63ef7e7

Browse files
nadaramouhzi
authored andcommitted
Issue 46 (#55)
* CurlFile fix This is not tested, but we are facing the same problem with CurlFile Uploads (#46) - This *should* do the trick. * Update README.md * cs fix
1 parent d2f085d commit 63ef7e7

File tree

2 files changed

+35
-21
lines changed

2 files changed

+35
-21
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# PHP Curl Class
22

3+
[![Build Status](https://travis-ci.org/php-mod/curl.svg?branch=master)](https://travis-ci.org/php-mod/curl)
4+
35
This library provides an object-oriented wrapper of the PHP cURL extension.
46

57
If you have questions or problems with installation or usage [create an Issue](https://github.com/php-mod/curl/issues).
@@ -115,7 +117,7 @@ fclose($file_handle);
115117
```
116118

117119

118-
## Testing
120+
## Testing
119121

120122
In order to test the library:
121123

src/Curl/Curl.php

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,9 @@ public function addResponseHeaderLine($curl, $header_line)
190190

191191
if ($trimmed_header === "") {
192192
$this->response_header_continue = false;
193-
} else if (strtolower($trimmed_header) === 'http/1.1 100 continue') {
193+
} elseif (strtolower($trimmed_header) === 'http/1.1 100 continue') {
194194
$this->response_header_continue = true;
195-
} else if (!$this->response_header_continue) {
195+
} elseif (!$this->response_header_continue) {
196196
$this->response_headers[] = $trimmed_header;
197197
}
198198

@@ -232,7 +232,19 @@ protected function preparePayload($data)
232232
$this->setOpt(CURLOPT_POST, true);
233233

234234
if (is_array($data) || is_object($data)) {
235-
$data = http_build_query($data);
235+
$skip = false;
236+
foreach ($data as $key => $value) {
237+
// If a value is an instance of CurlFile skip the http_build_query
238+
// see issue https://github.com/php-mod/curl/issues/46
239+
// suggestion from: https://stackoverflow.com/a/36603038/4611030
240+
if ($value instanceof \CurlFile) {
241+
$skip = true;
242+
}
243+
}
244+
245+
if (!$skip) {
246+
$data = http_build_query($data);
247+
}
236248
}
237249

238250
$this->setOpt(CURLOPT_POSTFIELDS, $data);
@@ -499,28 +511,28 @@ public function setOpt($option, $value)
499511
return curl_setopt($this->curl, $option, $value);
500512
}
501513

502-
/**
503-
* Get customized curl options.
504-
*
505-
* To see a full list of options: http://php.net/curl_getinfo
506-
*
507-
* @see http://php.net/curl_getinfo
508-
*
509-
* @param int $option The curl option constante e.g. `CURLOPT_AUTOREFERER`, `CURLOPT_COOKIESESSION`
510-
* @param mixed $value The value to check for the given $option
511-
*/
514+
/**
515+
* Get customized curl options.
516+
*
517+
* To see a full list of options: http://php.net/curl_getinfo
518+
*
519+
* @see http://php.net/curl_getinfo
520+
*
521+
* @param int $option The curl option constante e.g. `CURLOPT_AUTOREFERER`, `CURLOPT_COOKIESESSION`
522+
* @param mixed $value The value to check for the given $option
523+
*/
512524
public function getOpt($option)
513525
{
514526
return curl_getinfo($this->curl, $option);
515527
}
516528

517-
/**
518-
* Return the endpoint set for curl
519-
*
520-
* @see http://php.net/curl_getinfo
521-
*
522-
* @return string of endpoint
523-
*/
529+
/**
530+
* Return the endpoint set for curl
531+
*
532+
* @see http://php.net/curl_getinfo
533+
*
534+
* @return string of endpoint
535+
*/
524536
public function getEndpoint()
525537
{
526538
return $this->getOpt(CURLINFO_EFFECTIVE_URL);

0 commit comments

Comments
 (0)