$url = "https://example.com"
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$output = curl_exec($ch);
curl_close($ch);
📖️️La liste des options possibles est extrêmement complète : https://www.php.net/manual/fr/function.curl-setopt.php.
📖️️Le code n'est pas de moi et provient d'un stackoverflow : https://stackoverflow.com/a/49617294
function downloadFile($url, $filePath)
{
//echo "Retrieving http header...";
$header = get_headers("$url");
$pp = "0";
//echo json_encode($header, JSON_PRETTY_PRINT);
$key = key(preg_grep('/\bLength\b/i', $header));
$type = key(preg_grep('/\bType\b/i', $header));
$http = substr($header[0], 9, 3);
$tbytes = @explode(" ",$header[$key])[1];
$type = @explode("/",explode(" ",$header[$type])[1])[1];
$targetSize = floor((($tbytes / 1000)/1000))." Mo";
//echo " Target size: ".floor((($tbytes / 1000)/1000))." Mo || ".floor(($tbytes/1000))." Kb";
$t = explode("/",$url);
$remote = fopen($url, 'r');
$local = fopen($filePath, 'w');
$read_bytes = 0;
//echo PHP_EOL;
while(!feof($remote)) {
$buffer = fread($remote, intval($tbytes));
fwrite($local, $buffer);
$read_bytes += 2048;
$progress = min(100, 100 * $read_bytes / $tbytes);
$progress = substr($progress,0 , 6) *4;
$shell = 10; /* Progress bar width */
$rt = $shell * $progress / 100;
echo "\033[35;2m\e[0m Downloading '$url' : [".round($progress,3)."%] ".floor((($read_bytes/1000)*4))."Kb Total:" . $targetSize;
if ($pp === $shell){$pp=0;};
if ($rt === $shell){$rt=0;};
echo str_repeat("█",$rt).str_repeat("=",($pp++)).">@\r";
usleep(1000);
}
//echo " \033[35;2m\e[0mDone [100%] ".floor((($tbytes / 1000)/1000))." Mo || ".floor(($tbytes/1000))." Kb \r";
echo PHP_EOL;
fclose($remote);
fclose($local);
}