Skip to content

Instantly share code, notes, and snippets.

@ar-android
Created July 7, 2017 07:13
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ar-android/c5b612c47631216cb0be722ea5640627 to your computer and use it in GitHub Desktop.
Save ar-android/c5b612c47631216cb0be722ea5640627 to your computer and use it in GitHub Desktop.
Download file using guzzle
<?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];
}
}
@gnumoksha
Copy link

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.

http://docs.guzzlephp.org/en/latest/request-options.html#sink

@apkmaze
Copy link

apkmaze commented May 11, 2020

Anything new ?

@peter279k
Copy link

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