2024-11-10 03:40:05 +01:00
|
|
|
<?php
|
|
|
|
|
2024-11-11 01:21:06 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
2024-11-11 01:21:06 +01:00
|
|
|
* @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 {
|
|
|
|
|
2024-11-20 04:21:28 +01:00
|
|
|
$ch = \curl_init($fileSource);
|
2024-11-10 03:40:05 +01:00
|
|
|
|
2024-11-20 04:21:28 +01:00
|
|
|
$fp = \fopen($fileDestination, 'wb');
|
2024-11-10 03:40:05 +01:00
|
|
|
|
2024-11-20 04:21:28 +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
|
|
|
|
2024-11-20 04:21:28 +01:00
|
|
|
\curl_exec($ch);
|
|
|
|
$info = \curl_getinfo($ch);
|
2024-11-10 03:40:05 +01:00
|
|
|
|
2024-11-20 04:21:28 +01:00
|
|
|
\curl_close($ch);
|
|
|
|
\fclose($fp);
|
2024-11-10 03:40:05 +01:00
|
|
|
|
2024-11-11 01:21:06 +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
|
|
|
|
|
|
|
}
|