Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
You may know how to handle file inputs in PHP with cURL, as we've discussed earlier but GuzzleHTTP Client comes for the rescue to overcome messy code and get things done in more cleaner manner.
You may know how to handle file inputs in PHP with cURL, as we've discussed earlier.
But GuzzleHTTP Client comes for the rescue to overcome messy code and get things done in more cleaner manner.
$file = Input::file( 'file_name' );
$imagePath = $file->getPathName();
$tmp = tempnam( sys_get_temp_dir(), 'php' );
$client = new Client();
$result = $client->post( 'mydomain.com/api/endpoint', [
'form_params' =>
[
'file_name' => $tmp,
'name' => $file,
'contents' => file_put_contents( $tmp, file_get_contents( $imagePath ) ),
'filename' => $file
],
'headers' =>
[
'authorization' => 'Bearer ' . $token
]
] );
$results = \GuzzleHttp\json_decode( $result->getBody() );Easy peasy ? Ever wondered on handling multiple set of files with GuzzleHTTP over an API call? We've got you covered, do give it a read at
Try this yourself & leave us a comment below if you get stuck somewhere in between. Do follow us on Twitter.