S
S
Soft_touch_plastic2021-06-07 17:44:12
PHP
Soft_touch_plastic, 2021-06-07 17:44:12

Why is the document not sent via telegram api?

Hello, my bot should be able to send files to the chat, I put together the code to send the file:

$document = new CURLFile('test.txt');
        $url = "https://api.telegram.org/bot$token/sendDocument?chat_id=$chat_id";
        echo $url;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, ["document" => $document]);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type:multipart/form-data"]);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $out = curl_exec($ch);
        $err = curl_error($ch);
        curl_close($ch);
        var_dump($out);
        var_dump($err);

As a result, $out contains false, $err is empty! Why doesn't the page even return an error response? The URL is going to be correct, if you click on it, then a page opens with an error there is no document in the request. What is the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wagoodoogoo, 2021-06-17
@wagoodooogoo

most likely something with $document, trynew CURLFile(realpath("/path/to/test.txt"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question