Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonbernard/9002227 to your computer and use it in GitHub Desktop.
Save simonbernard/9002227 to your computer and use it in GitHub Desktop.
It took me some time so I would like to share with you: How-to download a file with PHP's cURL and afterwards continue with other cURL requests which return their output as usual.
$fh = fopen('/your/target/file', 'w');
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_URL, 'http://your/download/url');
curl_exec($ch);
// revert it
curl_setopt($this->ch, CURLOPT_FILE, STDOUT);
fclose($fh); // don't forget to close the handle
// important if you want to get the output of the next requests
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment