Advertisement
qwqweasd

Untitled

May 11th, 2022
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.34 KB | None | 0 0
  1. function p($var) {echo '<pre>';print_r($var);echo '</pre>';}
  2. function e($var) {echo "<br>";echo $var;echo "<br>";}
  3. // Путь и имя файла на нашем сервере.
  4. $file = __DIR__ . '/video/10.52.12-10.55.42[M][0@0][0]-1.mp4';
  5.  
  6. // Папка на Яндекс Диске
  7. $path = '/cam/';
  8.  
  9. // Запрашиваем URL для загрузки.
  10. $ch = curl_init('https://cloud-api.yandex.net/v1/disk/resources/upload?path=' . urlencode($path . basename($file)));
  11. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth ' . $token));
  12. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  13. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  14. curl_setopt($ch, CURLOPT_HEADER, false);
  15. $res = curl_exec($ch);
  16. curl_close($ch);
  17. p($res);
  18. $res = json_decode($res, true);
  19. if (empty($res['error'])) {
  20.     // Если ошибки нет, то отправляем файл на полученный URL.
  21.     $fp = fopen($file, 'r');
  22.  
  23.     $ch = curl_init($res['href']);
  24.     curl_setopt($ch, CURLOPT_PUT, true);
  25.     curl_setopt($ch, CURLOPT_UPLOAD, true);
  26.     curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));
  27.     curl_setopt($ch, CURLOPT_INFILE, $fp);
  28.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  29.     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  30.     curl_setopt($ch, CURLOPT_HEADER, false);
  31.     curl_exec($ch);
  32.     p(curl_getinfo($ch));
  33.     curl_close($ch);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement