从表单输入中上传照片和文本,并使用php发送到电报bot

问题描述 投票:0回答:1

html代码:

<form action="process.php">
     <input type="text" name="name">
 <input type="file" name="photo">
 <input type="submit" value="Submit">
</form>  

process.php:

define ('url',"https://api.telegram.org/bot****/");

$name = $_GET['name'];
$img=$_FILES['photo']['name'];
$chat_id = '****';
$message = urlencode("Name:".$name);
file_get_contents(url."sendmessage?text=".$message."&chat_id=".$chat_id."&parse_mode=HTML");

我收到短信,但没有照片。我不知道如何使用“ sendPoto”方法发送照片。

php telegram-bot photo send
1个回答
0
投票
您应将图像保存在服务器中,然后将直接下载链接传递给电报。像这样:

//TODO save uploded photo on myfiles/avatar1.png // send to telegram file_get_contents("https://api.telegram.org/bot****/sendPhoto?chat_id=1245763214&photo=http://example.com/myfiles/avatar1.png");

读取sendPhoto文档here
© www.soinside.com 2019 - 2024. All rights reserved.