Forked from devNoiseConsulting/gist:fb6195fbd09bfb2c1f81367dd9e727ed
Last active
December 13, 2021 19:29
-
-
Save muhammadsikandarkhatri/9ab734456a95dff5014e1f31a8ddcad0 to your computer and use it in GitHub Desktop.
Download large files using Guzzle 6.3
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 | |
require __DIR__ . '/vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
$url = "https://domain.tld/large-file.mp4"; | |
$tmpFile = tempnam(sys_get_temp_dir(), 'guzzle-download'); | |
$handle = fopen($tmpFile, 'w'); | |
$client = new Client(array( | |
'base_uri' => '', | |
'verify' => false, | |
'sink' => storage_path('file.mp4'), | |
'curl.options' => array( | |
'CURLOPT_RETURNTRANSFER' => true, | |
'CURLOPT_FILE' => $handle | |
) | |
)); | |
$client->get($url); | |
fclose($handle); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment