mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 04:01:47 +00:00
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:
+5
-7
@@ -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));
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user