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

34 lines
898 B
PHP

<?php
/**
* Namespace for PHP-CURL related classes and functions.
* @package NAE\Functions\Curl
*/
namespace NAE\Functions\Curl;
/**
* Lädt eine Dei herunter mit Hilfe von php-curl.
* @param string $fileDestination Zielpfad
* @param string $fileSource Quellpfad/URL
* @return bool Download Erfolgreich? (only works when the file size is known upfront from headers)
*/
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"] ); // only works when the file size is known upfront from headers
}