发送 xls 文件 Telegram 机器人

Send xls file Telegram bot

我正在尝试发送 xls 文件。上网查了2个小时,也没搞清楚哪里出错了。 我正在尝试从 url 发送此文件。这是我的代码

$filePath = $dburl."Last_season.xls";
$document = new CURLFile($filePath);
$post = array('chat_id' => $callback_id_username,'document'=> $document,'caption' => $caption);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$GLOBALS[website]."/sendDocument");
curl_setopt($ch, CURLOPT_POST, 1);   
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result_curl = curl_exec ($ch);
curl_close ($ch);

目前不支持通过 url 发送 xls 文件。

Sending by URL - In sendDocument, sending by URL will currently only work for gif, pdf and zip files.

查看机器人 API sending files

要解决此问题,您可以先将 xls 文件存储在您的系统上并使用此文件 - 而不是 url。

一种方法:

$url_of_file = $dburl."Last_season.xls";
$file_name = basename($url_of_file);
file_put_contents( $file_name,file_get_contents($file_name)); //store xls file named "Last_season.xls" locally
$document = new CURLFile($file_name);
$post_data = ["chat_id" => ADMIN_CHAT_ID, "document" => $document];