I want to make a function to send an image using Telegram API (reference API: https://github.com/mgp25/Telegram-Bot-API/), but when I try to run this, I always get an error like this:
Message: file_get_contents(''): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
Here is my code [updated]:
<?php
require 'Telegram.php';
$tele = new telegramBot('token');
//$info = $tele->sendMessage('218945828',"wadaw");
$url= 'image/maldini.jpg';
$info = $tele->sendPhoto('chatid',$url);
print_r($info);
?>
error :
Warning: file_get_contents(https://api.telegram.org/bot_token/sendPhoto?chat_id=chat_id&photo=0): failed to open stream: php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\htdocs\mgp25\Telegram-Bot-API-master\src\Telegram.php on line 465
What's wrong with my code?
Do you have SSL connection with Telegram? If you did not have SSL connection with telegram, non of telegram commands will not work but if you can send just a simple message so there is no SSL problem. After all if everything is OK except image,use this cURL code except using that ready to use
telegramBOT
class. if this is not working (cURL) , so there is really problem in reading from or finding photo on your server(Real server or xampp folder or so on...) If it is server(host) it MUST be upload first and if it is xampp image must be in true folder. it is better to test if image is accessible (for example via http://localhost/image/maldini.jpg from webbrowser?cURL Ready to use code for sending photo:
I think urlencode('http://127.0.0.1/mgp25/maldini.jpg'); is the problem. You should use your provider/public IP address. Or use a relative path.