function base_PUT()
{
if ($this->_check_lock_status($this->_path))
{
$options = array(
'path' => $this->_path,
'content_length' => $_SERVER['CONTENT_LENGTH']);
if (isset($_SERVER['CONTENT_TYPE']))
{
if (!strncmp($_SERVER['CONTENT_TYPE'], 'multipart/', 10))
{
$errMessage = 'The service does not support mulipart PUT requests';
$this->ThrowError('501 not implemented', 'WEBDAV_PUT_MULTIPART', $errMessage, __FILE__.' '.__LINE__);
echo $errMessage;
return;
}
$options['content_type'] = $_SERVER['CONTENT_TYPE'];
}
else
{
$options['content_type'] = 'application/octet-stream';
}
foreach ($_SERVER as $key => $val)
{
if (strncmp($key, "HTTP_CONTENT", 11))
continue;
switch ($key)
{
case 'HTTP_CONTENT_ENCODING':
$errMessage = "The service does not support '".htmlspecialcharsEx($val)."' content encoding";
$this->ThrowError('501 not implemented', 'WEBDAV_PUT_ENCODING', $errMessage, __FILE__.' '.__LINE__);
echo $errMessage;
return;
case 'HTTP_CONTENT_LANGUAGE':
$options["content_language"] = $val;
break;
case 'HTTP_CONTENT_LENGTH':
if (empty($options["content_length"])):
$options["content_length"] = $_SERVER['HTTP_CONTENT_LENGTH'];
$_SERVER['CONTENT_LENGTH'] = $_SERVER['HTTP_CONTENT_LENGTH'];
endif;
break;
case 'HTTP_CONTENT_LOCATION':
break;
case 'HTTP_CONTENT_TYPE':
break;
case 'HTTP_CONTENT_RANGE':
if (!preg_match('@bytess+(d+)-(d+)/((d+)|*)@', $val, $matches)) {
$errMessage = "The service does only support single byte ranges";
$this->ThrowError("400 bad request", 'WEBDAV_PUT_MULTIRANGE', $errMessage, __FILE__.' '.__LINE__);
echo $errMessage;
return;
}
$range = array(
"start"=>$matches[1],
"end"=>$matches[2]);
if (is_numeric($matches[3]))
{
$range["total_length"] = $matches[3];
}
$options["ranges"][] = $range;
break;
case 'HTTP_CONTENT_MD5':
$errMessage = 'The service does not support content MD5 checksum verification';
$this->ThrowError('501 not implemented', 'WEBDAV_PUT_MD5', $errMessage, __FILE__.' '.__LINE__);
echo $errMessage;
return;
default:
$errMessage = "The service does not support '".htmlspecialcharsEx($key)."'";
$this->ThrowError('501 not implemented', 'WEBDAV_PUT_MISC', $errMessage, __FILE__.' '.__LINE__);
echo $errMessage;
return;
}
}
$arPath = explode("/", $this->_udecode($options['path']));
foreach ($this->meta_names as $sMetaType => $arMetaProps)
{
if ($arPath[1] == $arMetaProps["alias"] &&
isset($arMetaProps["disable"]) &&
mb_strpos($arMetaProps["disable"], 'PUT') !== false
)
{
$this->ThrowAccessDenied();
return false;
}
}
$options['stream'] = fopen('php://input', 'r');
$stat = $this->PUT($options);
if ($stat === false)
{
$stat = $this->ThrowError('403 Forbidden', 'WEBDAV_PUT_PUT_FORBIDDEN', '', __FILE__.' '.__LINE__);
}
elseif (is_resource($stat) && get_resource_type($stat) == 'stream')
{
@set_time_limit(0);
$stream = $stat;
$stat = $options['new'] ? '201 Created' : '204 No Content';
if (!empty($options['ranges']))
{
if (0 == fseek($stream, $range[0]['start'], SEEK_SET))
{
$length = $range[0]['end']-$range[0]['start']+1;
if (!fwrite($stream, fread($options['stream'], $length)))
{
$stat = $this->ThrowError('403 Forbidden', 'WEBDAV_PUT_FWRITE_FAIL', '', __FILE__.' '.__LINE__);
}
}
else
{
$stat = $this->ThrowError('403 Forbidden', 'WEBDAV_PUT_SEEK_FAIL', '', __FILE__.' '.__LINE__);
}
}
else
{
while (!feof($options['stream']))
{
if (false === fwrite($stream, fread($options['stream'], 8192)))
{
$stat = $this->ThrowError('403 Forbidden', 'WEBDAV_PUT_FWRITE_FAIL2', '', __FILE__.' '.__LINE__);
break;
}
}
}
fclose($stream);
if (method_exists($this, 'put_commit') && !$this->put_commit($options))
{
$stat = $this->ThrowError('409 Conflict', 'WEBDAV_PUT_COMMIT_FAIL', '', __FILE__.' '.__LINE__);
}
}
self::set_header('Content-length: 0');
self::set_header('Location: ' . $this->base_url_full.$this->_path);
$this->SetStatus($stat);
}
else
{
$this->ThrowError('423 Locked', 'WEBDAV_PUT_LOCKED', '', __FILE__.' '.__LINE__);
}
}