- Модуль: webdav
- Путь к файлу: ~/bitrix/modules/webdav/classes/general.php
- Класс: CWebDavBase
- Вызов: CWebDavBase::SendFile
function SendFile(&$options, $download = null)
{
if($download == null)
{
$download = array_key_exists("force_download", $_REQUEST);
}
$status = null;
if (!headers_sent())
{
$fullPath = "";
if(array_key_exists("logica_full_path", $options))
{
$fullPath = $options["logica_full_path"];
}
if($this->Type == "iblock" && isset($this->arParams["fullpath"]) && $this->arParams["fullpath"] <> '')
{
$fullPath = $this->arParams["fullpath"];
}
elseif($this->Type == "folder" && $this->real_path_full <> '')
{
$fullPath = $this->real_path_full;
}
if($fullPath <> '')
{
$arT = self::GetMimeAndGroup($fullPath);
$options['mimetype'] = $arT["mime"];
}
else
{
$options['mimetype'] = 'application/octet-stream';
$download = true;
}
/*
if ($options['mimetype'] == 'application/zip') // fix old magic.mime
$options['mimetype'] = $this->get_mime_type($options['path']);*/
if (
(
$GLOBALS["APPLICATION"]->IsHTTPS()
&& mb_substr($options['mimetype'], 0, 11) == "application"
)
|| $this->http_user_agent == "ie"
)
{
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
$options["cache_time"] = 0;
}
$status = '200 OK';
$name = "";
if (!empty($options["name"]))
{
$name = $options["name"];
}
else
{
$res = explode("/", $this->_udecode($options["path"]));
$name = end($res);
}
if ($this->http_user_agent == "ie")
{
$name = $this->_uencode($name, array("utf8" => "Y", "convert" => "full"));
}
elseif (SITE_CHARSET != 'UTF-8')
{
$name = $GLOBALS['APPLICATION']->ConvertCharset($name, SITE_CHARSET, 'UTF-8');
}
self::set_header('Content-type: ' . $options['mimetype']);
self::set_header('Content-Disposition: filename="'.$name.'"', true);
self::set_header('ETag: "' . $this->_get_etag() . '"');
if(array_key_exists("cache_time", $options) && $options["cache_time"] > 0 && mb_substr($options['mimetype'], 0, 6) == "image/")
{
//Handle ETag
if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && $this->_check_etag($_SERVER['HTTP_IF_NONE_MATCH']))
{
$this->SetStatus('304 Not Modified');
self::set_header("Cache-Control: private, max-age=".$options["cache_time"].", pre-check=".$options["cache_time"]);
die();
}
//Handle Last Modified
if($options["mtime"] > 0)
{
$lastModified = gmdate('D, d M Y H:i:s', $options["mtime"]).' GMT';
if(array_key_exists("HTTP_IF_MODIFIED_SINCE", $_SERVER) && ($_SERVER['HTTP_IF_MODIFIED_SINCE'] === $lastModified))
{
$this->SetStatus('304 Not Modified');
self::set_header("Cache-Control: private, max-age=".$options["cache_time"].", pre-check=".$options["cache_time"]);
die();
}
}
self::set_header("Cache-Control: private, max-age=".$options["cache_time"].", pre-check=".$options["cache_time"]);
}
$userNavigator = CUserOptions::GetOption('webdav', 'navigator', array('platform'=>'Win'));
if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && // for correct save action in MS Office 2010
$this->_check_etag($_SERVER['HTTP_IF_NONE_MATCH']) &&
(
mb_strpos($_SERVER['HTTP_USER_AGENT'], 'Microsoft') !== false &&
mb_strpos($userNavigator['platform'], 'Win') !== false
)
)
{
$this->SetStatus('304 Not Modified');
die();
}
if (!$download)
{
if($fullPath <> '')
{
$download = !self::CanViewFile($fullPath, false);
}
else
{
$download = true;
}
}
if ($download == true)
{
self::set_header('Content-Disposition: attachment; filename="'.$name.'"', true);
}
if (isset($options['mtime']))
{
self::set_header('Last-modified: '.gmdate('D, d M Y H:i:s ', $options['mtime']).'GMT');
}
session_write_close();
if (isset($options['stream']))
{
$sizeO = intval($options['size']);
$ranges = (isset($options['ranges']) && is_array($options['ranges'])) ? $options['ranges'] : array();
$this->SendFileFromStream($options['stream'], $options['mimetype'], $sizeO, $ranges);
}
elseif (isset($options['data']) && !is_array($options['data']))
{
self::set_header('Content-length: ' . $this->strlen($options['data']));
echo $options['data'];
}
}
return $status;
}