Eleirbag89 / TelegramBotPHP

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

how to download file #56

Closed mjavidm closed 7 years ago

mjavidm commented 7 years ago

hi, i'm using this code but not work. "file_path" is empty code: $result = $telegram->getData(); $doc_id = $result["message"]["document"] ["file_id"]; $file = $telegram->getFile($doc_id); $telegram->downloadFile($file["file_path"], "./3333333.xls");

i'm sending *.xls files to bot and saved in host but file size is: 0 plz help me tnks

Eleirbag89 commented 7 years ago

Check if the values of $doc_id and $file seems correct. Then we will investigate about the download function.

mjavidm commented 7 years ago

yes $doc_id values is hash code like "AgADBAADdKgxG66mEVABIZqHNFIk-PqAAEsAgABAg" $file values is "Array" But $file["file_path"] & $file[0] & $file[1] & $file[2] => output is not show

Eleirbag89 commented 7 years ago

try this:

$result = $telegram->getData();
$doc_id = $result["message"]["document"] ["file_id"];
$file = $telegram->getFile($doc_id);
$response = print_r($file, true);
$content = array('chat_id' => $chat_id, 'text' => $response);
$telegram->sendMessage($content);

I think there is some error in the telegram response.

Eleirbag89 commented 7 years ago

I found the problem. I think telegram changed the response from the get file. You should use:

$telegram->downloadFile($file["result"]["file_path"], "./3333333.xls");
mjavidm commented 7 years ago

$telegram->downloadFile($file["result"]["file_path"], "./3333333.xls"); it's true very good, thank you