使用bot在Telegram上载文件 [英] Upload file on Telegram with bot

查看:667
本文介绍了使用bot在Telegram上载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Telegram Bots将URL中的文件发送给用户,.attheme中的我的文件扩展名,但是我无法从Url上传此文件.

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.

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

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

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

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

我该怎么做?

推荐答案

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

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.

通过URL发送
在sendDocument中,当前仅通过URL发送 适用于gif,pdf和zip文件. [doc]

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


用PHP发送文件


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

这篇关于使用bot在Telegram上载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆