Answer the question
In order to leave comments, you need to log in
How to save photos sent by a user?
Hello.
I can manage to work with one photo, but I don’t quite understand how to save how many photos that are in one message. The bottom line is that I need to accept one or more pictures from the user and send them to other chats.
I use telebot.
Answer the question
In order to leave comments, you need to log in
# Было загружено ФОТО
if ( isset($result["message"]["photo"]) OR isset($result["message"]["document"]) ) {
if (isset($result["message"]["photo"])) {
$file_id = $result['message']['photo'][count($result['message']['photo']) - 1]['file_id'];
}elseif (isset($result["message"]["document"])) {
$file_id = $result['message']['document']['file_id'];
}else{
}
$res_f = $telegram->getFile(['file_id' => $file_id]);
// ссылка на файл в телеграме
$file_path = $res_f["file_path"];
$file_from_tgrm = "https://api.telegram.org/file/bot".config::$botToken."/".$file_path;
// достаем расширение файла
$tmp = explode(".", $file_path);
$ext = end($tmp);
// назначаем свое имя здесь время_в_секундах.расширение_файла
$name_our_new_file = time().".".$ext;
copy($file_from_tgrm, "images/".$name_our_new_file);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question