public static function downloadFile(string $url) : string
    {
        $downloadedFilepath = tempnam(sys_get_temp_dir(), "");
        
        // use curl if installed. Faster and probably more memory efficient.
        if (function_exists('curl_version'))
        {
            $fp = fopen($downloadedFilepath, 'w+');
            $ch = curl_init(str_replace(" ", "%20", $url));
            curl_setopt($ch, CURLOPT_TIMEOUT, 50);
            curl_setopt($ch, CURLOPT_FILE, $fp); 
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_exec($ch); 
            curl_close($ch);
            fclose($fp);
        }
        else
        {
            $content = file_get_contents($url);
            file_put_contents($downloadedFilepath, $content);
        }
        
        return $downloadedFilepath;
    }