Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
file.php
1<?php
2
4
5
7
9{
10 protected $path;
14 protected $name;
18 protected $contentType;
19 protected $showInline = false;
20 protected $cacheTime = 0;
21
22 public function __construct($path, $name = null, $contentType = 'application/octet-stream')
23 {
24 parent::__construct();
25
26 $this->setPath($path);
28
29 if ($name === null)
30 {
31 $name = bx_basename($path);
32 }
33
34 $this->setName($name);
35 }
36
40 public function getPath()
41 {
42 return $this->path;
43 }
44
50 public function setPath($path)
51 {
52 $this->path = $path;
53
54 return $this;
55 }
56
60 public function getName()
61 {
62 return $this->name;
63 }
64
70 public function setName($name)
71 {
72 $this->name = $name;
73
74 return $this;
75 }
76
80 public function getContentType()
81 {
82 return $this->contentType;
83 }
84
90 public function setContentType($contentType)
91 {
92 $this->contentType = $contentType;
93
94 return $this;
95 }
96
100 public function isShowInline()
101 {
102 return $this->showInline;
103 }
104
110 public function showInline($enabled)
111 {
112 $this->showInline = (bool)$enabled;
113
114 return $this;
115 }
116
120 public function getCacheTime()
121 {
122 return $this->cacheTime;
123 }
124
130 public function setCacheTime($cacheTime)
131 {
132 $this->cacheTime = (int)$cacheTime;
133
134 return $this;
135 }
136
137 protected function prepareOptions()
138 {
139 return [
140 'force_download' => !$this->isShowInline(),
141 'cache_time' => $this->getCacheTime(),
142 'attachment_name' => $this->getName(),
143 'content_type' => $this->getContentType(),
144 'fast_download' => false,
145 ];
146 }
147
148 protected function prepareFile()
149 {
150 $path = new \Bitrix\Main\IO\File($this->getPath());
151
152 return \CFile::makeFileArray($path->getPhysicalPath());
153 }
154
155 public function send()
156 {
157 \CFile::viewByUser($this->prepareFile(), $this->prepareOptions());
158 }
159}
__construct($path, $name=null, $contentType='application/octet-stream')
Definition file.php:22
setContentType($contentType)
Definition file.php:90