Upload file on Telegram with bot

白昼怎懂夜的黑 提交于 2019-12-11 01:47:01

问题


I want to send file from URL to user with Telegram Bots, My files extension in .attheme but I can't upload this files from Url.

Currently I can upload .zip , .pdf, but i want upload a .attheme file from PHP code.

This bot can upload any type of files into Telegram: @uploadbot

How can I do this ?


回答1:


Sending a file by URL only works for certaining file types. If you want to upload other types of files you will have to post the file, after saving it on your own server, using multipart/form-data.

Sending by URL
In sendDocument, sending by URL will currently only work for gif, pdf and zip files. [doc]


Sending file in PHP

$filepath = realpath('folder/.attheme');
$post = array('chat_id' => $GLOBALS["chat_id"],'document'=>new CurlFile($filepath));    
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://api.telegram.org/bot" . $GLOBALS["token"] . "/sendDocument");
curl_setopt($ch, CURLOPT_POST, 1);   
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec ($ch);
curl_close ($ch); 


来源:https://stackoverflow.com/questions/49731046/upload-file-on-telegram-with-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!