Advertisement
turbocode

Untitled

Jan 19th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 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. class YandexDisk {
  8.     private $token = 'token';
  9.     private $header = array();
  10.     private $curl;
  11.    
  12.     function __construct() {
  13.         $this->header = array('Accept: application/json','Authorization: OAuth '.$this->token);
  14.         $this->curl = curl_init();
  15.         curl_setopt($this->curl, CURLOPT_HTTPHEADER, $this->header);
  16.         curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, 1);
  17.         curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
  18.         curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false);
  19.         curl_setopt($this->curl, CURLOPT_SSL_VERIFYHOST, false);
  20.     }
  21.    
  22.    
  23.     public function uploadFile($url,$name) {  
  24.             $url = "https://cloud-api.yandex.net/v1/disk/resources/upload?path=$name.mp3&url=$url&overwrite=true";
  25.             curl_setopt($this->curl, CURLOPT_URL, $url);
  26.             curl_setopt($this->curl, CURLOPT_POST, 1);
  27.             $result = curl_exec($this->curl);
  28.             curl_close($this->curl);
  29.             return $result;
  30.    
  31.     }
  32.    
  33.     public function createFolder($name) {
  34.             $url = "https://cloud-api.yandex.net/v1/disk/resources/?path=$name";
  35.             curl_setopt($this->curl, CURLOPT_URL, $url);
  36.             curl_setopt($this->curl, CURLOPT_PUT, true);
  37.             $result = curl_exec($this->curl);
  38.             curl_close($this->curl);
  39.             return $result;      
  40.     }
  41.    
  42.     public function getUrl($id) {
  43.         $url = "https://cloud-api.yandex.net/v1/disk/resources?path=$name";
  44.         curl_setopt($this->curl, CURLOPT_URL, $url);
  45.         curl_setopt($this->curl, CURLOPT_PUT, true);
  46.         $result = curl_exec($this->curl);
  47.         curl_close($this->curl);
  48.        
  49.         return $result;      
  50.     }
  51.    
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement