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

34 lines
907 B
PHP
Raw Permalink Normal View History

2024-11-10 03:40:05 +01:00
<?php
/**
* Namespace for PHP-CURL related classes and functions.
* @package NAE\Functions\Curl
*/
2024-11-10 03:40:05 +01:00
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)
2024-11-10 03:40:05 +01:00
*/
function downloadFile(string $fileDestination, string $fileSource) : bool {
$ch = \curl_init($fileSource);
2024-11-10 03:40:05 +01:00
$fp = \fopen($fileDestination, 'wb');
2024-11-10 03:40:05 +01:00
\curl_setopt($ch, CURLOPT_FILE, $fp);
\curl_setopt($ch, CURLOPT_HEADER, 0);
\curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
2024-11-10 03:40:05 +01:00
\curl_exec($ch);
$info = \curl_getinfo($ch);
2024-11-10 03:40:05 +01:00
\curl_close($ch);
\fclose($fp);
2024-11-10 03:40:05 +01:00
return ( $info["download_content_length"]==$info["size_download"] ); // only works when the file size is known upfront from headers
2024-11-10 03:40:05 +01:00
}