如何修复tmhOAuth.php(twitter)中不推荐的:curl_setopt()

如何修复tmhOAuth.php(twitter)中不推荐的:curl_setopt(),php,curl,twitter,deprecated,Php,Curl,Twitter,Deprecated,我使用PHP版本5.5.9 尝试将图像发布到twitter,但我有以下警告: Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in C:\xampp\htdocs\project_folder\libs\tmhOAuth\tmhOAuth.php on line 771 当我检查文件t

我使用PHP版本5.5.9

尝试将图像发布到twitter,但我有以下警告:

Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in C:\xampp\htdocs\project_folder\libs\tmhOAuth\tmhOAuth.php on line 771
当我检查文件tmhOAuth.php上的脚本时,如下所示:

758    $c = curl_init();
759    switch ($this->request_settings['method']) {
760      case 'GET':
761        if (isset($this->request_settings['querystring']))
762          $this->request_settings['url'] = $this->request_settings['url'] . '?' . $this->request_settings['querystring'];
763        break;
764      case 'POST':
765        curl_setopt($c, CURLOPT_POST, true);
766        if (isset($this->request_settings['postfields']))
767          $postfields = $this->request_settings['postfields'];
768        else
769          $postfields = array();
770
771        curl_setopt($c, CURLOPT_POSTFIELDS, $postfields);
772        break;
773      default:
774        if (isset($this->request_settings['postfields']))
775          curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->request_settings['postfields']);
776    }

如何修复此问题?

您需要使用函数
curl\u file\u create()处理所有文件,,
f、 e


当我使用curl\u file\u create时,我有一个警告“可捕获的致命错误:类CURLFile的对象无法转换为字符串..”$image=“C:/xampp/htdocs/project\u folder/photos/small\u 1412933689.jpg”$img=curl\u file\u create($image)$code=$tmhOAuth->user_请求(数组('method'=>'POST','url'=>'','params'=>array('media[]'=>“@.$img.”type=image/jpeg;filename={$imagename},'status'=>$\u SESSION['content\u text']),'multipart=>true))@a、 fauzi删除“媒体[]”中的所有文本=>。。它只需要$img,就像这样
..'media[]'=>$img,'status'=>..
<?php
    $path = '/path/to/file';
    $file = curl_file_create($path);
    $c = curl_init();
    curl_setopt($c, CURLOPT_POSTFIELDS, array('file' => $file));