2014-10-10 107 views
0

我使用PHP版本5.5.9如何解决不推荐使用:在tmhOAuth.php curl_setopt()(Twitter)上

尝试发布图片到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 } 

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

回答

0

您需要使用功能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]

+0

当我使用curl_file_create我有这样的警告“开捕致命错误:类CURLFile的对象无法转换为字符串。” – 2014-10-10 09:47:28

+0

@ a.fauzi以显示你的代码'curl_file_create' – fiction 2014-10-10 09:51:23

+0

$ image =“C:/xampp/htdocs/project_folder/photos/small_1412933689.jpg”; $ img = curl_file_create($ image); $ code = $ tmhOAuth-> user_request(array( 'method'=>'POST', 'url'=>“https://api.twitter.com/1.1/statuses/update_with_media.json”, ' params'=> array( 'media []'=>“@”。$ img。“; type = image/jpeg; filename = {$ imagename}”, 'status'=> $ _SESSION ['content_text'] ), 'multipart'=> true )); – 2014-10-10 10:18:16

相关问题