Skip to content

Instantly share code, notes, and snippets.

@romainneutron
Created April 8, 2013 21:59
Show Gist options
  • Save romainneutron/5340930 to your computer and use it in GitHub Desktop.
Save romainneutron/5340930 to your computer and use it in GitHub Desktop.
Download large files using Guzzle
<?php
use Guzzle\Http\Client;
require __DIR__ . '/vendor/autoload.php';
$tmpFile = tempnam(sys_get_temp_dir(), 'guzzle-download');
$handle = fopen($tmpFile, 'w');
$client = new Client('', array(
Client::CURL_OPTIONS => array(
'CURLOPT_RETURNTRANSFER' => true,
'CURLOPT_FILE' => $handle
)
));
$client->get('http://domain.tld/large-file.mp4')->send();
fclose($handle);
@devNoiseConsulting
Copy link

I forked this gist to use Guzzle 6.3. https://gist.github.com/devNoiseConsulting/fb6195fbd09bfb2c1f81367dd9e727ed
I still need to test with large files, but the code will write the file to disk.

@muhammadsikandarkhatri
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment