Created
July 7, 2017 07:13
-
-
Save ar-android/c5b612c47631216cb0be722ea5640627 to your computer and use it in GitHub Desktop.
Download file using guzzle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Download { | |
public function download($url, $name, $extensions){ | |
$path = __DIR__.'/download/' . $name . $extensions; | |
$file_path = fopen($path,'w'); | |
$client = new \GuzzleHttp\Client(); | |
$response = $client->get($url, ['save_to' => $file_path]); | |
return ['response_code'=>$response->getStatusCode(), 'name' => $name]; | |
} | |
} |
Anything new ?
According to the official Guzzle doc, it seems that the save_to
request option is deprecated since the 6.5+
version has been released, and it should use the sink
option instead.
The detailed deprecated message is as follows:
Note
The save_to request option has been deprecated in favor of the sink request option. Providing the save_to option is now an alias of sink.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://docs.guzzlephp.org/en/latest/request-options.html#sink