<?php
include_once('vendor/autoload.php');
$uri = 'https://geocode-maps.yandex.ru/1.x/?apikey=API_KEY&geocode=%D0%A1%D0%B0%D0%BD%D0%BA%D1%82-%D0%9F%D0%B5%D1%82%D0%B5%D1%80%D0%B1%D1%83%D1%80%D0%B3';
$use_errors = libxml_use_internal_errors(true);
$xml = simplexml_load_file($url);
if (false === $xml) {
echo "Failed loading XML\n";
foreach(libxml_get_errors() as $error) {
echo "\t", $error->message;
}
}
$fragSize = 10485760;
$fileSize = filesize(Cb::FILES_DIR . '/' . $taskId . '.' . $data['folder'] . '/' . $data['Name']);
$numFragments = ceil($fileSize / $fragSize);
$bytesRemaining = $fileSize;
$i = 0;
$ch = curl_init($uploadUrl);
while ($i < $numFragments) {
$chunkSize = $numBytes = $fragSize;
$start = $i * $fragSize;
$end = $i * $fragSize + $chunkSize - 1;
$offset = $i * $fragSize;
if ($bytesRemaining < $chunkSize) {
$chunkSize = $numBytes = $bytesRemaining;
$end = $fileSize - 1;
}
if ($stream = fopen(Cb::FILES_DIR . '/' . $taskId . '.' . $data['folder'] . '/' . $data['Name'], 'r')) {
// get contents using offset
$result = stream_get_contents($stream, $chunkSize, $offset);
fclose($stream);
}
$headers['Accept'] = 'application/json, application/soap+xml';
$headers['Content-Type'] = 'application/octet-stream';
$headers['Content-Length'] = $numBytes;
$headers['Content-Range'] = $content_range;
curl_setopt($ch, CURLOPT_URL, $uploadUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
//curl_setopt($ch, CURLOPT_HEADER, false);
//curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
//curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $result);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERPWD, $this->apiAuthLogin . ":" . $this->apiAuthPassword);
$server_output = curl_exec($ch);
$info = curl_getinfo($ch);
$bytesRemaining = $bytesRemaining - $chunkSize;
$i++;
}
тогда как /api нормально работает с options