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

时间:2014-10-10 09:11:20

标签: 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

当我检查文件上的脚本时,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    }

我该如何解决这个问题??

1 个答案:

答案 0 :(得分:1)

您需要使用函数curl_file_create();处理所有文件, f.e。

<?php
    $path = '/path/to/file';
    $file = curl_file_create($path);
    $c = curl_init();
    curl_setopt($c, CURLOPT_POSTFIELDS, array('file' => $file));

link to man [curl_file_create]