Skip to content

Instantly share code, notes, and snippets.

@gundamew
Last active June 13, 2022 18:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gundamew/f04bdf2e2850eb73df2621d67f1fef32 to your computer and use it in GitHub Desktop.
Save gundamew/f04bdf2e2850eb73df2621d67f1fef32 to your computer and use it in GitHub Desktop.
Download/Upload files with Guzzle.
<?php
$client = new GuzzleHttp\Client();
// Ref: https://guzzle.readthedocs.io/en/latest/request-options.html#sink-option
$client->request('GET', 'http://example.com', [
'sink' => '/tmp/' . sha1(file_get_contents('https://example.com'))
]);
<?php
$client = new GuzzleHttp\Client();
$client->request('POST', 'https://example.com', [
'multipart' => [
[
'name' => 'foo',
'contents' => fopen('/path/to/file', 'r'),
],
],
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment