Post files does not work (php7.1)
Closed this issue · 3 comments
POSTing files does not work as intended.
This is what I'd like to do:
$file = new \CURLFile($filePath, mime_content_type($filePath), 'file_post_name');
$data = array(
'mode' => 'import',
'file' => $file,
);
$this->curl->setHeader('Accept', 'application/json');
$this->curl->setHeader('Content-Type', 'application/json');
$this->curl->post('http://example.com', $data);
$this->curl->close();
However what is posted is a string representation of the data, including the CURLFile instance, not the actual file. I.e:
mode=import&file%5Bname%5D=path/to/file/&file%5Bmime%5D=mime_type_of_file&file%5Bpostname%5D=file_post_name
This is due to the preparePayload
method - that runs http_build_query
on the data. If I remove those lines everything works as expected.
The library should include a way to skip http_build_query
, or a special method for adding a file to the posted data.
Thanks
Faced the same problem
@danielsetreus We could isolate the array keys which are an instanceof \CURLFile and add them after processing the http_build_query() data?
@danielsetreus https://github.com/php-mod/curl/pull/53/files this should fix the problem - right?