我正在尝试构建一个电报机器人,但问题与更新的 php 5.6 导致的 php 函数变化有关。
下面是我找到的基本代码,可适应 php 5.6 中的更改。
#$filePhoto = curl_file_create($filepath, 'image/jpg', 'heInternet'); //**LINE 39**
$filePhoto = new CURLFile($filepath, 'image/jpg', 'heInternet'); //**LINE 40**
//$texto = $_POST['msg'];
$content = array(
'chat_id' => "@BugTheInternet",
'photo' => $filePhoto
);
//curl required to post
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); // required as of PHP 5.6.0
curl_setopt($ch, CURLOPT_POSTFIELDS, $filePhoto); //**LINE 53**
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //fix http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
// receive server response ...
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
这是我得到的错误:
不推荐使用:curl_setopt():不推荐使用 @filename API 进行文件上传。请在第 53 行的 C:\xampp 某处\somefile.php 中使用 CURLFile 类
当我在第 53 行将 $content 更改为 $filePhoto 时。它运行并且 Telegram 服务器以 JSON 格式发送消息。服务器回复:
"{"ok":false,"error_code":400,"description":"Error: Bad Request: there is no photo in request"}"
我已经在互联网上搜索了几个小时,寻找解决方案。顺便说一句,我为我正在使用的 PHP 5.6 建议了两种方法,它在第 39、40 行。
如果您遇到这种情况或其他情况,请帮助我。谢谢你。