Skip to content

Instantly share code, notes, and snippets.

@abrahamfast
Created August 18, 2020 10:29
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 abrahamfast/41367d257b5abe4dca2e86d6517bf776 to your computer and use it in GitHub Desktop.
Save abrahamfast/41367d257b5abe4dca2e86d6517bf776 to your computer and use it in GitHub Desktop.
download file from url
<?php
$url = 'url'
$fileName = basename($url);
$filePath = __DIR__ . "/downloaded/" . $fileName);
$file = fopen($filePath, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1200);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FILE, $file);
$result = curl_exec($ch);
if(!$result) {
echo "Error :-: ".curl_error($ch);
}
curl_close($ch);
return $filePath;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment