PHP-cli-factorio-updater/scripts/func.downloadFile.php

30 lines
648 B
PHP
Raw Normal View History

2024-11-10 03:40:05 +01:00
<?php
namespace NAE\Functions\Curl;
/**
* Lädt eine Dei herunter mit Hilfe von php-curl.
* @param string Zielpfad
* @param string Quellpfad/URL
* @return bool Download Erfolgreich?
*/
function downloadFile(string $fileDestination, string $fileSource) : bool {
$ch = curl_init($fileSource);
$fp = fopen($fileDestination, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
fclose($fp);
return ( $info["download_content_length"]==$info["size_download"] );
}