doulong4169 2015-12-22 16:51
浏览 41

谷歌开发者控制台中的CURL php

I'm using Google Developers Console to build a bot for telegram.

everything works fine, except that when I try to send files (photo, audio, etc ..) php returns a fatal error for the lack of libraries Curl.

I checked and this is the php version 5.5.26, and also supports the new function CURLFile.

How can I fix?

I leave you the error that returns the console

1 - Method

    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 Fatal error: Class 'CURLFile' not found in /base/data/home/apps/s~macabreobot/1.389444928540417808/main.php on line 18

2 Method

    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 Fatal error: Call to undefined function curl_init() in /base/data/home/apps/s~macabreobot/1.389445039709239473/main.php on line 36

  • 写回答

1条回答 默认 最新

  • dosin84644 2015-12-24 03:50
    关注

    There are some configuration steps needed to use curl_ functions on App Engine PHP, see Terrence Ryan's blog post on the subject for more details.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大