Telegram::downloadFile PHP Method

downloadFile() public method

\param $telegram_file_path String File path on Telegram servers \param $local_file_path String File path where save the file
public downloadFile ( $telegram_file_path, $local_file_path )
    public function downloadFile($telegram_file_path, $local_file_path)
    {
        $file_url = "https://api.telegram.org/file/bot" . $this->bot_id . "/" . $telegram_file_path;
        $in = fopen($file_url, "rb");
        $out = fopen($local_file_path, "wb");
        while ($chunk = fread($in, 8192)) {
            fwrite($out, $chunk, 8192);
        }
        fclose($in);
        fclose($out);
    }

Usage Example

Exemplo n.º 1
1
            $reply = "Private Chat";
        }
        // Create option for the custom keyboard. Array of array string
        $option = array(array("A", "B"), array("C", "D"));
        // Get the keyboard
        $keyb = $telegram->buildKeyBoard($option);
        $content = array('chat_id' => $chat_id, 'reply_markup' => $keyb, 'text' => $reply);
        $telegram->sendMessage($content);
    }
    if ($text == "/git") {
        $reply = "Check me on GitHub: https://github.com/Eleirbag89/TelegramBotPHP";
        // Build the reply array
        $content = array('chat_id' => $chat_id, 'text' => $reply);
        $telegram->sendMessage($content);
    }
    if ($text == "/img") {
        // Load a local file to upload. If is already on Telegram's Servers just pass the resource id
        $img = curl_file_create('test.png', 'image/png');
        $content = array('chat_id' => $chat_id, 'photo' => $img);
        $telegram->sendPhoto($content);
        //Download the file just sended
        $file_id = $message["photo"][0]["file_id"];
        $file = $telegram->getFile($file_id);
        $telegram->downloadFile($file["file_path"], "./test_download.png");
    }
    if ($text == "/where") {
        // Send the Catania's coordinate
        $content = array('chat_id' => $chat_id, 'latitude' => "37.5", 'longitude' => "15.1");
        $telegram->sendLocation($content);
    }
}