[英]How can I send photos from external address to my channel?
I need send photos from an external address to my channel: 我需要将照片从外部地址发送到我的频道:
and I have a code for send text to channel: 我有一个代码用于向频道发送文本:
$bot_token = '*****';
$channel_name = '@******';
$content = urlencode("{$message}");
$url = "https://api.telegram.org/bot{$bot_token}/sendMessage?chat_id={$channel_name}&parse_mode=html&disable_web_page_preview=false&text={$content}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close($ch);
return $response;
How can I send photos from external address to my channel?? 如何将照片从外部地址发送到我的频道? (in getUpdates method) (在getUpdates方法中)
You need to save the file on your server first, for example with file_get_contents
and file_put_contents
您需要首先将文件保存在服务器上,例如,使用file_get_contents
和file_put_contents
$imgUrl = "<image url>";
$path = "tmp/img.png"; //location on your server to save the image
$image = file_get_contents($imgURL); //get the image
file_put_contents($path, $image); //save the image on your server
Afterwards you can post the image you saved to the telegram api 之后,您可以将保存的图像发布到电报api中
$url = "https://api.telegram.org/bot" . $bot_token . "/sendPhoto";
$filepath = realpath($path);
//Set post data
$post = array('chat_id' => $channel_name ,'photo'=>new CURLFile($filepath));
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_exec ($ch);
curl_close ($ch);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.