themattharris / tmhOAuth

An OAuth 1.0A library written in PHP
Apache License 2.0
855 stars 335 forks source link

curl_setopt(): The usage of the @filename API for file uploading is deprecated #180

Closed ryanjkoehler closed 10 years ago

ryanjkoehler commented 10 years ago

I'm receiving the warning:

curl_setopt(): The usage of the @filename API for file uploading is deprecated Please use the CURLFile class instead in tmhOAuth.php on line 787 using PHP 5.5.3

when using update_with_media to upload a photo:

$temp_file = $_POST['url']; // this is path of local file $temp_type = $_POST['type']; // jpg $temp_name = $_POST['name']; // image.jpg

$tmhOAuth = new tmhOAuth( array( 'consumer_key' => $POST['consumerkey'], 'consumer_secret' => $POST['consumersecret'], 'user_token' => $POST['usertoken'], 'user_secret' => $POST['usersecret'], ));

$params = array( 'media[]' => "@{$temp_file};type={$temp_type};filename={$temp_name}", 'status' => $_POST['status'] );

$code = $tmhOAuth->request( 'POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', $params, true, // use auth true // multipart );

if ( $code == 200 ) { echo "success"; }else{ echo $code; }

vancanneyt commented 10 years ago

In PHP 5.6 it is deprecated resulting in tmhoauth not being able to upload an image to Twitter. Temporary workaround:

themattharris commented 10 years ago

which version of tmhOAuth are you using? 0.8.4 resolved issue #168 and added support for CurlFile. you do need to pass a CurlFile object though, for example:

$client->request('POST', 'https://api.twitter.com/1.1/statuses/update_with_media.json', array(
  'status' => 'Posting a photo',
  'media[]' => new CurlFile('my-file.jpg'),
), true, true);```