1

i'm trying to send a xls file. Looking online and after 2 hours, I didn't figure out where is it the error. I'm trying to send this file from an url. Here's my code

$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);
Erry215
  • 326
  • 1
  • 4
  • 15

1 Answers1

4

Sending xls files via url is currently not supported.

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

See Bot API sending files.

To work around this issue you can first store the xls file on your system and use this file - instead of the url.

One way to do this:

$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];
newsha
  • 1,288
  • 1
  • 10
  • 13