html code:
<form action="process.php">
<input type="text" name="name">
<input type="file" name="photo">
<input type="submit" value="Submit">
</form>
process.php:
define ('url',"https://api.telegram.org/bot****/");
$name = $_GET['name'];
$img=$_FILES['photo']['name'];
$chat_id = '****';
$message = urlencode("Name:".$name);
file_get_contents(url."sendmessage?text=".$message."&chat_id=".$chat_id."&parse_mode=HTML");
I recieve text message but photo not. I don’t know how to send photo with “sendPoto” method.
2
Answers
You should save the image in your Server and then pass a direct downlaod link to telegram. like this:
Note: When sending by URL the target file must have the correct MIME type (e.g., audio/mpeg for sendAudio, etc.).
Read sendPhoto document here
First of all you must store the file uploaded.
in your
html
code you have error. you must addenctype='multipart/form-data'
to supportfile input
.So your
html
code must be like this:In your
php
file you must first save file uploaded.After that you can send this file to telegram api.