twitter-async
                                
                                 twitter-async copied to clipboard
                                
                                    twitter-async copied to clipboard
                            
                            
                            
                        EpiOAuth.php fails on PHP 5.5
On PHP v5.5, you get the error message: Deprecated: curl_setopt(): The usage of the @filename API for file uploading is deprecated. Please use the CURLFile class instead in .../EpiOAuth.php on line 270.
There needs to be a check for PHP v5.5 along the lines of:
if (function_exists('curl_file_create')) {
.... Curlfile() class code
} else {
.... Existing code
}
However, what is the correct code to use?
A quick fix (until this is depecrated) is to change function httpPost to read:
  protected function httpPost($url, $params = null, $isMultipart)
  {
    $this->addDefaultHeaders($url, $params['oauth']);
    $ch = $this->curlInit($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    // php's curl extension automatically sets the content type
    // based on whether the params are in string or array form
    if (function_exists('curl_file_create')) {
        curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false); // Allow PHP 5.5 to work as per original CURL
    }
    if($isMultipart){
      $params['request']['status'] = urldecode($params['request']['status']);
      @curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
    }else{
      curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
    }
    $resp = $this->executeCurl($ch);
    $this->emptyHeaders();
    return $resp;
  }
I did try using the following code to post media with images:
                            if (function_exists('curl_file_create')) {
                                $args=array();
                                $args['file'] = new CurlFile($offerImage, $imageType, basename($offerImage));
                                $args['status'] = $status;
                                $resp = $twitterObj->post('/statuses/update_with_media.json', $args);
                            } else {
                                $resp = $twitterObj->post('/statuses/update_with_media.json',
                                           array('@media[]'  => "@{$offerImage};type=$imageType;filename={$offerImage}",
                                                'status'   => $status));
                            }
However, that gives other errors within buildHttpQueryRaw() and encode_rfc3986() as the parameters now contain an object.
This is no longer valid in PHP 7 - "curl_setopt(): Disabling safe uploads is no longer supported"
So the whole routine will need to be re-written for PHP v7 - I understand that we need to use something along the lines of new \CURLFile($localFile)
Upon upgrading from PHP 5.4 straight to 5.6, we started getting this error when using the "@" upload syntax:
{"code":189,"message":"Error creating status."}
The fix above didn't help; we must be using the library a bit differently, or are perhaps using an outdate version.  I was able to fix the problem by simply adding the following line right before the return statement in EpiOAuth.php's curlInit($url) function:
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
Hope this helps someone else!