Core: Upload a picture to url, and send

Created on 3 Mar 2017  路  7Comments  路  Source: php-telegram-bot/core

Welcome to be the task with the link to download the image and send. I think it is easier, but nothing happened happened.
Code:
$image = $this->curl_get_contents("https://www.ru/data/resource_icons/0/{$id}.jpg"); file_put_contents("/var/www/www-root/data/www/www.ru/bots/test/Download/image.jpg" , $image);
try $this->telegram->getUploadPath(), and in other ways but failed to get a working effect it.
I will be very grateful for the example code

Most helpful comment

Please don't use 777, especially for a folder that allows user uploads!
755 should work perfectly too.

All 7 comments

Hi @opkiler22789
Not sure I totally understand. Do you want users to be able to send a link to your bot, which then downloads it into the upload folder?

@noplanman In general, the bot is integrated with the site and information is displayed, I also try to download links from the site to the directory and send to the chat

Ok, so you're trying to send a picture to a chat via the bot?

In that case you can do the following in the command's execute method:

return Request::sendPhoto([
        'chat_id' => $chat_id,
    ],
    '/path/to/your/image.jpg'
);

@noplanman and it, therefore, but the picture itself does not appear in the directory. file_put_contents is not working properly, and I do not see an error

Have you set your upload path properly in your hook.php file?

You should be able to use this to save the file to the right location:

file_put_contents($this->telegram->getUploadPath() . '/image.jpg', $image);

Also, make sure the folder exists and that the permissions are set properly!

Thank you gave permissions 777 folder everything worked

Please don't use 777, especially for a folder that allows user uploads!
755 should work perfectly too.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mohsenshahab picture mohsenshahab  路  4Comments

Recouse picture Recouse  路  3Comments

NabiKAZ picture NabiKAZ  路  4Comments

Zoha picture Zoha  路  3Comments

noplanman picture noplanman  路  3Comments