Merge pull request #260 from zachborboa/master

Fix #258: Allow sending request data with non-file values prefixed with the @ character
This commit is contained in:
Zach Borboa
2015-10-27 23:16:39 -07:00
2 changed files with 16 additions and 7 deletions
+5 -7
View File
@@ -105,15 +105,13 @@ class Curl
} else {
$binary_data = false;
foreach ($data as $key => $value) {
// Fix "Notice: Array to string conversion" when $value in
// curl_setopt($ch, CURLOPT_POSTFIELDS, $value) is an array
// that contains an empty array.
// Fix "Notice: Array to string conversion" when $value in curl_setopt($ch, CURLOPT_POSTFIELDS,
// $value) is an array that contains an empty array.
if (is_array($value) && empty($value)) {
$data[$key] = '';
// Fix "curl_setopt(): The usage of the @filename API for
// file uploading is deprecated. Please use the CURLFile
// class instead".
} elseif (is_string($value) && strpos($value, '@') === 0) {
// Fix "curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use
// the CURLFile class instead". Ignore non-file values prefixed with the @ character.
} elseif (is_string($value) && strpos($value, '@') === 0 && is_file(substr($value, 1))) {
$binary_data = true;
if (class_exists('CURLFile')) {
$data[$key] = new \CURLFile(substr($value, 1));
+11
View File
@@ -385,6 +385,17 @@ class CurlTest extends PHPUnit_Framework_TestCase
}
}
public function testPostNonFilePathUpload()
{
$test = new Test();
$test->server('post', 'POST', array(
'foo' => 'bar',
'file' => '@not-a-file',
));
$this->assertFalse($test->curl->error);
$this->assertEquals('foo=bar&file=%40not-a-file', $test->curl->response);
}
public function testPutRequestMethod()
{
$test = new Test();