Core: How to use sendDocument for multipart/form-data?

Created on 17 Nov 2017  路  4Comments  路  Source: php-telegram-bot/core

I want to send a CSV file created using PHP (and is not stored on the disk) via sendDocument method using multipart/form-data since it has no URL, but didn't find any guide about it.
Can someone plz help?

Most helpful comment

You need to send the resource, not contents
$data['document'] = fopen('file.xlsx', 'rb');

All 4 comments

You should be able to just pass your stream to the document parameter of sendDocument.
Does this work for you? #484

Yes, that worked great!

But when the file is stored on the disk, code below does not work.

$file = file_get_contents('file.xlsx');
$data['document'] = $file ;
$data['chat_id'] = 1234;
Request::sendDocument($data);

You need to send the resource, not contents
$data['document'] = fopen('file.xlsx', 'rb');

Thanks @sharkydog , I will try that out.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NabiKAZ picture NabiKAZ  路  3Comments

dorcu picture dorcu  路  3Comments

Recouse picture Recouse  路  3Comments

esomkin picture esomkin  路  3Comments

marcolino7 picture marcolino7  路  3Comments