hello guys, I know you may heard about Telegram bot API, and I want to use their API to send texts and photos, telegram API differs from bots API here is the full document about API https://core.telegram.org/bots/api
I want to send photo using curl but its fail always, sending text is easy since it take string patameters$sendmsg = "https://api.telegram.org/bot".$token."/sendMessage?chat_id=".$chat_id."&text=".$text."";
here is my try to send photos but it failes always, no error messages just no photos sent
if (isset($_POST['btnUpload']))
{
$token = <token here>;
$chat_id = "17446522";
$text = " Test ";
$filename = $_FILES['file']['name'];
$filedata = $_FILES['file']['tmp_name'];
$filesize = $_FILES['file']['size'];
if ($filedata != '')
{
$url = 'https://api.telegram.org/bot'.$token.'/sendPhoto';
$data = array('chat_id' => $chat_id, 'photo' => $filedata);
function multipart_build_query($fields, $boundary){
$retval = '';
foreach($fields as $key => $value){
$retval .= "--$boundary\r\nContent-Disposition: form-data; name=\"$key\"\r\n\r\n$value\r\n";
}
$retval .= "--$boundary--";
return $retval;
}
$boundary = '--myboundary-xxx';
$body = multipart_build_query($data, $boundary);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: multipart/form-data; boundary=$boundary"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$response = curl_exec($ch);
$message = json_decode($response, true);
echo "<pre>";
print_r($message);
echo "</pre>";
}
?>
<form action="" method="post" enctype="multipart/form-data">
<tr>
<td>Upload</td>
<td align="center">:</td>
<td><input name="file" type="file" id="file"/></td>
</tr>
<tr>
<td> </td>
<td align="center"> </td>
<td><input name="btnUpload" type="submit" value="Upload" /></td>
</tr>
</form>