使用机器人在 Telegram 上上传文件

Upload file on Telegram with bot

我想使用 Telegram Bots 从 URL 向用户发送文件,我的文件扩展名为 .attheme,但我无法从 Url.[=15= 上传此文件]

目前我可以上传 .zip.pdf,但我想从 PHP 代码上传 .attheme 文件。

此机器人可以将任何类型的文件上传到 Telegram:@uploadbot

我该怎么做?

通过 URL 发送文件仅适用于某些文件类型。如果您想上传其他类型的文件,您必须 post 文件,在将其保存在您自己的服务器上后,使用 multipart/form-data.

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


正在 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);