Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 KB | None | 0 0
  1. //Нужно чтобы эти настройки у курла были по умолчанию
  2.         //curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->header);
  3.         //curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
  4.        // curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
  5.        // curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
  6.         //curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
  7.  
  8. class YandexDisk {
  9.     private $token = 'AQAEA7qiKBKFAATDAPzhf55jkU3QlCext-2UxOw';
  10.     private $header = array();
  11.     private $curl;
  12.    
  13.     function __construct() {
  14.         $this->header = array('Accept: application/json','Authorization: OAuth '.$this->token);
  15.         $this->curl = curl_init();
  16.         curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->header);
  17.         curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
  18.         curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
  19.         curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
  20.         curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
  21.     }
  22.    
  23.    
  24.     public function uploadFile($url,$name) {  
  25.             $url = "https://cloud-api.yandex.net/v1/disk/resources/upload?path=$name.mp3&url=$url&overwrite=true";
  26.             curl_setopt($this->curl, CURLOPT_URL, $url);
  27.             curl_setopt($this->curl, CURLOPT_POST, 1);
  28.             $result = curl_exec($this->curl);
  29.             curl_close($this->curl);
  30.             return $result;
  31.    
  32.     }
  33.    
  34.     public function createFolder($name) {
  35.             $url = "https://cloud-api.yandex.net/v1/disk/resources/?path=$name";
  36.             curl_setopt($this->curl, CURLOPT_URL, $url);
  37.             curl_setopt($this->curl, CURLOPT_PUT, true);
  38.             $result = curl_exec($this->curl);
  39.             curl_close($this->curl);
  40.             return $result;      
  41.     }
  42.    
  43.     public function getUrl($id) {
  44.         $url = "https://cloud-api.yandex.net/v1/disk/resources?path=$name";
  45.         curl_setopt($this->curl, CURLOPT_URL, $url);
  46.         curl_setopt($this->curl, CURLOPT_PUT, true);
  47.         $result = curl_exec($this->curl);
  48.         curl_close($this->curl);
  49.        
  50.         return $result;      
  51.     }
  52.    
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement