M
M
mt_max2017-06-09 10:13:05
PHP
mt_max, 2017-06-09 10:13:05

Get requests, working with telegram api - PHP?

good evening. I want to implement sending a site form to telegram, several text fields and a picture. I wrote this script for articles and lessons ... in general, here I call the send () function 2 times to make a request to the api, the first time everything is fine, the message comes, I get the answer, the second time I call the same function, with a different parameter to send a photo and it doesn’t seem to be running, curl doesn’t return anything, the request itself is tested correctly through the browser and the picture flies away. what am I doing wrong

the code
<?php
$p1= $_POST['name'];
$p2= $_POST['email'];
$p3=  $_POST['reg_phone'];
$p4= $_POST['reg_education'];
$chatid="371194029";
$url="адрес сайта";
 
$mes="https://api.telegram.org/bot:мойтокен/sendMessage?chat_id=$chatid&text=$p1%0A$p2%0A$p3%0A$p4%0A";
echo "$mes";echo"<br>";
send($mes);
 
$uploaddir = 'user_files/';
$uploadfile = $uploaddir . basename($_FILES['f']['name']);
 
 
 
if(is_uploaded_file($_FILES["f"]["tmp_name"]))
   {
     // Если файл загружен успешно, перемещаем его
     // из временной директории в конечную
     move_uploaded_file($_FILES["f"]["tmp_name"],
                        "user_files/".$_FILES["f"]["name"]);
                        $senphoto="https://api.telegram.org/bot:мойтокенHezRjN3bZe9_uVaNZ4tXE/sendPhoto?chat_id=$chatid&photo=$url/user_files/".$_FILES["f"]["name"];                       
                        send($sendPhoto);
                        echo "$senphoto";                       
    
   } else {
      echo("error");
   }
 
function send($url)
{
// создание нового ресурса cURL
$ch = curl_init();
// установка URL и других необходимых параметров
curl_setopt($ch, CURLOPT_URL, "$url");
//а это что бы на страницу не выводилось
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
//это в справочнике прочтете
curl_setopt($ch, CURLOPT_HEADER, 0);
// загрузка страницы и выдача её браузеру другими словами при открытии страницы где вы этот скрипт сделаете автоматически отправится сообщение в заданный вами телеграм чат.
 
$data=curl_exec($ch);
echo "$data";
echo"<br><br><br><br><br>";
// завершение сеанса и освобождение ресурсов
 
curl_close($ch);
}
 
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Burov, 2017-06-09
@mt_max

$senphoto="https://api.telegram.org/bot:мойтокенHezRjN3bZe9_uVaNZ4tXE/sendPhoto?chat_id=$chatid&photo=$url/user_files/".$_FILES["f"]["name"];                       
                        send($sendPhoto);

Variable se np hoto, and in send pass sen dP hoto
to avoid this, turn on error output and warning

N
Nastya Sukharik, 2017-06-09
@nastya_cyxarik

and where did you find sendPhoto in api???
maybe this was meant https://core.telegram.org/method/messages.editChatPhoto

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question