Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function p($var) {echo '<pre>';print_r($var);echo '</pre>';}
- function e($var) {echo "<br>";echo $var;echo "<br>";}
- // Путь и имя файла на нашем сервере.
- $file = __DIR__ . '/video/10.52.12-10.55.42[M][0@0][0]-1.mp4';
- // Папка на Яндекс Диске
- $path = '/cam/';
- // Запрашиваем URL для загрузки.
- $ch = curl_init('https://cloud-api.yandex.net/v1/disk/resources/upload?path=' . urlencode($path . basename($file)));
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: OAuth ' . $token));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_HEADER, false);
- $res = curl_exec($ch);
- curl_close($ch);
- p($res);
- $res = json_decode($res, true);
- if (empty($res['error'])) {
- // Если ошибки нет, то отправляем файл на полученный URL.
- $fp = fopen($file, 'r');
- $ch = curl_init($res['href']);
- curl_setopt($ch, CURLOPT_PUT, true);
- curl_setopt($ch, CURLOPT_UPLOAD, true);
- curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));
- curl_setopt($ch, CURLOPT_INFILE, $fp);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_exec($ch);
- p(curl_getinfo($ch));
- curl_close($ch);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement