Eleirbag89 / TelegramBotPHP

A very simple PHP Telegram Bot API for sending messages.
http://eleirbag89.github.io/TelegramBotPHP
MIT License
800 stars 340 forks source link

Download file issue #204

Closed dnsBlah closed 3 years ago

dnsBlah commented 4 years ago

Hi all,

I'm not sure why this is an issue, unless the ssl from the api endpoint is getting issues. In multiple other issue's people note that they can't download files, and/or end up with 0kb files. My issue had nothing to do with either filename call or anything, I just always take the last 'file' to be sure I'm downloading the original one.

I noticed that fopen() failed on ssl verification. For testing purposes I adjusted the downloadFile function and it worked straight away.

public function downloadFile($telegram_file_path, $local_file_path)
    {
        $file_url = 'https://api.telegram.org/file/bot'.$this->bot_token.'/'.$telegram_file_path;
//Added the below stream options
        $opts=array(
                "ssl"=>array(
                        "verify_peer"=>false,
                        "verify_peer_name"=>false,
                ),
        );
//Added the stream options to this remote fopen()
        $in = fopen($file_url, 'rb', false, stream_context_create($opts));
...
...
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.