Last active
December 2, 2022 12:48
-
-
Save edutrul/9d04d7742545dbedd1a36f7b17632b7a to your computer and use it in GitHub Desktop.
How to download a file programmatically using guzzle in Drupal 8 / Drupal 9
This file contains 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 | |
$external_file = 'https://www.example.com/test.png' | |
$destination = 'sites/default/files/a-directory/test.png'; | |
/** @var GuzzleHttp\Psr\Response $response */ | |
$response = \Drupal::httpClient()->get($external_file, ['sink' => $destination]); | |
// file gets downloaded under /sites/default/files/a-directory/test.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment