public static function downloadFile(File $file)
{
$tg_file_path = $file->getFilePath();
$file_path = self::$telegram->getDownloadPath() . '/' . $tg_file_path;
$file_dir = dirname($file_path);
//For safety reasons, first try to create the directory, then check that it exists.
//This is in case some other process has created the folder in the meantime.
if (!@mkdir($file_dir, 0755, true) && !is_dir($file_dir)) {
throw new TelegramException('Directory ' . $file_dir . ' can\'t be created');
}
$debug_handle = TelegramLog::getDebugLogTempStream();
try {
self::$client->get('/file/bot' . self::$telegram->getApiKey() . '/' . $tg_file_path, ['debug' => $debug_handle, 'sink' => $file_path]);
return filesize($file_path) > 0;
} catch (RequestException $e) {
return (string) $e->getResponse()->getBody();
} finally {
//Logging verbose debug output
TelegramLog::endDebugLogTempStream("Verbose HTTP File Download Request output:\n%s\n");
}
}