[英]How can I get my website to send an email to someone from my address upon submit?
[英]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_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
之后,您可以將保存的圖像發布到電報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.