Closed elimentz closed 7 years ago
Done in v 6.12.0, see documentation for details:
For sending files via a POST request, you can use the withFile
method to correctly format a request before sending:
use Ixudra\Curl\Facades\Curl;
$response = Curl::to('http://foo.com/bar')
->withData( array( 'Foo' => 'Bar' ) )
->withFile( 'image_1', '/path/to/dir/image1.png', 'image/png', 'imageName1.png' )
->withFile( 'image_2', '/path/to/dir/image2.png', 'image/png', 'imageName2.png' )
->post();
You can add as many files to the request as you want. A couple of things to keep in mind:
asJson()
method and asJsonRequest()
method cannot be used. If you do, the files will not be transferred correctlywithData()
method using the first parameter of the withFile()
method. If this key already exists, it will be overridden.
PHP 5.5 introduced a CurlFile object that deprecates the old @filename syntax See: https://wiki.php.net/rfc/curl-file-upload for details