I am trying to convert excel file to base64 to send WhatsApp API with Ultramsg :
<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to="";
$filename="test.xlsx";
$document = base64_encode(file_get_contents("test.xlsx"));
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);
But I see this error :
Array
(
[error] => Array
(
[0] => Array
(
[document] => file extension not supported
)
)
)
CodePudding user response:
You need add MIME types for Microsoft Excel .xls=application/vnd.ms-excel or .xlsx=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
So , Try this code block and enjoy (: :
<?php
require_once ('vendor/autoload.php'); // if you use Composer
//require_once('ultramsg.class.php'); // if you download ultramsg.class.php
$token=""; // Ultramsg.com token
$instance_id=""; // Ultramsg.com instance id
$client = new UltraMsg\WhatsAppApi($token,$instance_id);
$to="";
$filename="test.xlsx";
$document = base64_encode(file_get_contents("test.xlsx"));
$document ="data:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;base64,".$document;
$api=$client->sendDocumentMessage($to,$filename,$document);
print_r($api);