我正在使用Google Developers Console为电报构建机器人。
一切正常,除了当我尝试发送文件(照片,音频等等)时,php会因缺少库Curl而返回致命错误。
我检查了这是php版本5.5.26,并且还支持新功能CURLFile。
我该如何解决?
我告诉你返回控制台的错误
1 - 方法
function sendIMG($api_url,$path,$chatID)
{
$url = $api_url."sendPhoto?chat_id=".$chatID ;
$post_fields = array(
'chat_id' => $chatID,
'photo' => new \CURLFile(realpath($path))
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
$output = curl_exec($ch);
sendText($api_url, $chatID, $output);
}
PHP致命错误:Class' CURLFile'在第18行的/base/data/home/apps/s~macabreobot/1.389444928540417808/main.php中找不到
2方法
function sendIMG_2($api_url,$path,$chatID)
{
$api_url = "https://api.telegram.org/botYOUR_BOT_TOKEN/";
$url = $api_url."sendPhoto?chat_id=".$chatID;
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:multipart/form-data"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("photo" => "@".$path));
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($path));
$output = curl_exec($ch);
sendText($api_url, $chatID, $output);
}
PHP致命错误:在第36行的/base/data/home/apps/s~macabreobot/1.389445039709239473/main.php中调用未定义的函数curl_init()