如何将照片从外部地址发送到我的频道?

How can I send photos from external address to my 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;

如何从外部地址发送照片到我的频道?? (在 getUpdates 方法中)

您需要先将文件保存在您的服务器上,例如 file_get_contentsfile_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

之后你可以post你保存到电报的图片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);