I use MadelineProto
I need to get a photo from the last post in telegram
The code I use:
<?php
if (!file_exists('madeline.php')) {
copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');
}
include 'madeline.php';
$MadelineProto = new danogMadelineProtoAPI('session.madeline');
$MadelineProto->start();
$channel = '@example';
$offset_id = 0;
$limit = 1;
$messages_Messages = $MadelineProto->messages->getHistory(['peer' => $channel, 'offset_id' => $offset_id, 'offset_date' => 0, 'add_offset' => 0, 'limit' => $limit, 'max_id' => 0, 'min_id' => 0, 'hash' => 0 ]);
$message = $messages_Messages['messages'][0];
echo json_encode($message);
$MadelineProto->downloadToFile($message, "/tmp.png");
$message :
{"_":"messageMediaPhoto","photo":{"_":"photo","has_stickers":false,"id":5**54901******2695,"access_hash":-82*****8334,"file_reference":{"_":"bytes","bytes":"AkV4QiEAABFvYFze*****QoZFrTBH7fvQ="},"date":1616692497,"sizes":[{"_":"photoStrippedSize","type":"i","bytes":{"_":"bytes","bytes":"ASgdpA8dV/EU0n*****FFJjTA=="}},{"_":"photoSize","type":"m","location":{"_":"fileLocationToBeDeprecated","volume_id":4****0743,"local_id":44***85},"w":231,"h":320,"size":12760},{"_":"photoSize","type":"x","location":{"_":"fileLocationToBeDeprecated","volume_id":4000****43,"local_id":44***6},"w":502,"h":696,"size":36269}],"dc_id":4}}
The data on the photo comes in, but the file is not created, what is the problem?
2
Answers
As it turned out in the end Madeline is going a little crazy
You just had to add the DIR constant
Last line of code:
I had the same problem but with the downlowntodir() method .(no diffrences)
as you see , if you just add a dot followed by a slash ‘./ ‘ the bot will download the file in the same directory where your ‘bot.php‘ is placed .(in my case it’s downloaded to ‘downloads‘ dirctory which is at the same directory where ‘bot.php‘ is placed .
or you can