PHP:无法使用cURL上传文件。在其他字段中使用@的错误

时间:2015-12-06 11:33:15

标签: php curl telegram-bot

我正在尝试使用cURL将照片发送到Telegram bot API但是当我在chat_id字段中使用“@”时,我收到此错误:
Deprecated: curl_setopt_array(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class

这是我的代码:

$post = array('chat_id' => '@ameer_test', 'photo'=> new CURLFile('E:\wamp\www\test/content/uploads/sample.png'));
$curl = curl_init("https://api.telegram.org/bot122877145:AAH-mTygl1FeisuOnsESbCVerRqd6-DTxD0/sendPhoto");
curl_setopt_array($curl, array(
    //CURLOPT_HTTPHEADER => $headers,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_SSL_VERIFYHOST => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_SAFE_UPLOAD => 0,
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => $post
    ));
$response = curl_exec($curl);
curl_close($curl);
var_dump($response);

如何告诉cURL这个@不是文件名。

谢谢!

1 个答案:

答案 0 :(得分:0)

根据php手册:

  

通过将CURLOPT_SAFE_UPLOAD选项设置为TRUE,可以禁用@前缀以安全传递以@开头的值。