Answer the question
In order to leave comments, you need to log in
How to add a file to a variable in curl request?
Hello. I want to send a photo to telegram via curl. In PHP, to send a file with a relative path, you need to resort to this method:
function tg($method, $data) {
...
$cucu = curl_init("https://api.telegram.org/$token/$method");
...
}
$cfile = new CURLFile(realpath("file.jpg"));
$data['photo'] = $cfile;
tg('sendPhoto', $data);
$data['photo'] = "file.jpg";
Answer the question
In order to leave comments, you need to log in
--data-binary @filename
-F [email protected]_name
-d, --data HTTP POST data
--data-ascii HTTP POST ASCII data
--data-binary HTTP POST binary data
--data-raw HTTP POST data, '@' allowed
--data-urlencode HTTP POST data url encoded
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question