// Путь и имя файла на нашем сервере.
$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);
}
{"operation_id":"7e2b6a14dd92c1b***ce6a274b7c79","href":"https://uploader23o.disk.yandex.net:443/upload-target/20****-k23o.21296554","method":"PUT","templated":false}
Array
(
[url] => https://uploader23o.disk.y*******-k23o.21296554
[content_type] =>
[http_code] => 201
[header_size] => 558
[request_size] => 191
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 216.159022
[namelookup_time] => 0.058212
[connect_time] => 0.107571
[pretransfer_time] => 0.21516
[size_upload] => 28170127
[size_download] => 0
[speed_download] => 0
[speed_upload] => 130321
[download_content_length] => -1
[upload_content_length] => 28170127
[starttransfer_time] => 0.264434
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 37.9.68.214
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 10.0.0.207
[local_port] => 53774
[http_version] => 2
[protocol] => 2
[ssl_verifyresult] => 0
[scheme] => HTTPS
[appconnect_time_us] => 214949
[connect_time_us] => 107571
[namelookup_time_us] => 58212
[pretransfer_time_us] => 215160
[redirect_time_us] => 0
[starttransfer_time_us] => 264434
[total_time_us] => 216159022
)