1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
file.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Main\IO;
4
5
class
File
extends
FileEntry
implements
IFileStream
6
{
7
const
REWRITE
= 0;
8
const
APPEND
= 1;
9
11
protected
$filePointer
;
12
13
public
function
__construct
(
$path
,
$siteId
=
null
)
14
{
15
parent::__construct(
$path
,
$siteId
);
16
}
17
25
public
function
open
($mode)
26
{
27
$this->filePointer = fopen($this->
getPhysicalPath
(), $mode .
"b"
);
28
if
(!$this->filePointer)
29
{
30
throw
new
FileOpenException
($this->originalPath);
31
}
32
return
$this->filePointer;
33
}
34
40
public
function
close
()
41
{
42
if
(!$this->filePointer)
43
{
44
throw
new
FileNotOpenedException
($this->originalPath);
45
}
46
fclose($this->filePointer);
47
$this->filePointer =
null
;
48
}
49
50
public
function
isExists
()
51
{
52
if
($this->exists ===
null
)
53
{
54
$p
= $this->
getPhysicalPath
();
55
$this->exists = file_exists(
$p
) && (is_file(
$p
) || is_link(
$p
));
56
}
57
58
return
$this->exists;
59
}
60
61
public
function
getContents
()
62
{
63
if
(!$this->
isExists
())
64
{
65
throw
new
FileNotFoundException
($this->originalPath);
66
}
67
68
return
file_get_contents($this->
getPhysicalPath
());
69
}
70
71
public
function
putContents
(
$data
, $flags = self::REWRITE)
72
{
73
$dir
= $this->
getDirectory
();
74
if
(!
$dir
->isExists())
75
{
76
$dir
->create();
77
}
78
79
if
($this->
isExists
() && !$this->
isWritable
())
80
{
81
$this->
markWritable
();
82
}
83
84
$this->exists =
null
;
85
86
return
$flags & self::APPEND
87
? file_put_contents($this->
getPhysicalPath
(),
$data
, FILE_APPEND)
88
: file_put_contents($this->
getPhysicalPath
(),
$data
);
89
}
90
98
public
function
getSize
()
99
{
100
if
(!$this->
isExists
())
101
{
102
throw
new
FileNotFoundException
($this->originalPath);
103
}
104
105
static
$supportLarge32 =
null
;
106
if
($supportLarge32 ===
null
)
107
{
108
$supportLarge32 = (
\Bitrix\Main\Config\Configuration::getValue
(
"large_files_32bit_support"
) ===
true
);
109
}
110
111
$size = 0;
112
if
(PHP_INT_SIZE < 8 && $supportLarge32)
113
{
114
// 32bit
115
$this->
open
(
FileStreamOpenMode::READ
);
116
117
if
(fseek($this->filePointer, 0, SEEK_END) === 0)
118
{
119
$size = 0.0;
120
$step = 0x7FFFFFFF;
121
while
($step > 0)
122
{
123
if
(fseek($this->filePointer, -$step, SEEK_CUR) === 0)
124
{
125
$size += floatval($step);
126
}
127
else
128
{
129
$step >>= 1;
130
}
131
}
132
}
133
134
$this->
close
();
135
}
136
else
137
{
138
// 64bit
139
$size = filesize($this->
getPhysicalPath
());
140
}
141
142
return
$size;
143
}
144
152
public
function
seek
($position)
153
{
154
if
(!$this->filePointer)
155
{
156
throw
new
FileNotOpenedException
($this->originalPath);
157
}
158
159
if
($position <= PHP_INT_MAX)
160
{
161
return
fseek($this->filePointer, $position);
162
}
163
else
164
{
165
$res
= fseek($this->filePointer, 0);
166
if
(
$res
=== 0)
167
{
168
do
169
{
170
$offset = ($position < PHP_INT_MAX ? $position : PHP_INT_MAX);
171
$res
= fseek($this->filePointer, $offset, SEEK_CUR);
172
if
(
$res
!== 0)
173
{
174
break
;
175
}
176
$position -= PHP_INT_MAX;
177
}
178
while
($position > 0);
179
}
180
return
$res
;
181
}
182
}
183
184
public
function
isWritable
()
185
{
186
if
(!$this->
isExists
())
187
{
188
throw
new
FileNotFoundException
($this->originalPath);
189
}
190
191
return
is_writable($this->
getPhysicalPath
());
192
}
193
194
public
function
isReadable
()
195
{
196
if
(!$this->
isExists
())
197
{
198
throw
new
FileNotFoundException
($this->originalPath);
199
}
200
201
return
is_readable($this->
getPhysicalPath
());
202
}
203
204
public
function
readFile
()
205
{
206
if
(!$this->
isExists
())
207
{
208
throw
new
FileNotFoundException
($this->originalPath);
209
}
210
211
return
readfile($this->
getPhysicalPath
());
212
}
213
214
public
function
markWritable
()
215
{
216
if
(!$this->
isExists
())
217
{
218
throw
new
FileNotFoundException
($this->originalPath);
219
}
220
221
@chmod($this->
getPhysicalPath
(), BX_FILE_PERMISSIONS);
222
}
223
224
public
function
delete
()
225
{
226
if
($this->
isExists
())
227
{
228
$this->exists =
null
;
229
return
unlink($this->
getPhysicalPath
());
230
}
231
232
return
true
;
233
}
234
235
public
function
getContentType
()
236
{
237
if
(!$this->
isExists
())
238
{
239
throw
new
FileNotFoundException
($this->originalPath);
240
}
241
242
$finfo = \finfo_open(FILEINFO_MIME_TYPE);
243
$contentType
= \finfo_file($finfo, $this->
getPath
());
244
\finfo_close($finfo);
245
246
return
$contentType
;
247
}
248
249
public
static
function
isFileExists
(
$path
)
250
{
251
$f
=
new
self
(
$path
);
252
return
$f
->isExists();
253
}
254
255
public
static
function
getFileContents
(
$path
)
256
{
257
$f
=
new
self
(
$path
);
258
return
$f
->getContents();
259
}
260
261
public
static
function
putFileContents
(
$path
,
$data
, $flags = self::REWRITE)
262
{
263
$f
=
new
self
(
$path
);
264
return
$f
->putContents(
$data
, $flags);
265
}
266
267
public
static
function
deleteFile
(
$path
)
268
{
269
$f
=
new
self
(
$path
);
270
return
$f
->delete();
271
}
272
}
Bitrix\Main\Config\Configuration\getValue
static getValue($name)
Определения
configuration.php:24
Bitrix\Main\IO\FileEntry
Определения
fileentry.php:6
Bitrix\Main\IO\File\deleteFile
static deleteFile($path)
Определения
file.php:267
Bitrix\Main\IO\File\getContents
getContents()
Определения
file.php:61
Bitrix\Main\IO\File\open
open($mode)
Определения
file.php:25
Bitrix\Main\IO\File\APPEND
const APPEND
Определения
file.php:8
Bitrix\Main\IO\File\isReadable
isReadable()
Определения
file.php:194
Bitrix\Main\IO\File\isFileExists
static isFileExists($path)
Определения
file.php:249
Bitrix\Main\IO\File\isWritable
isWritable()
Определения
file.php:184
Bitrix\Main\IO\File\getSize
getSize()
Определения
file.php:98
Bitrix\Main\IO\File\seek
seek($position)
Определения
file.php:152
Bitrix\Main\IO\File\putFileContents
static putFileContents($path, $data, $flags=self::REWRITE)
Определения
file.php:261
Bitrix\Main\IO\File\putContents
putContents($data, $flags=self::REWRITE)
Определения
file.php:71
Bitrix\Main\IO\File\getFileContents
static getFileContents($path)
Определения
file.php:255
Bitrix\Main\IO\File\close
close()
Определения
file.php:40
Bitrix\Main\IO\File\getContentType
getContentType()
Определения
file.php:235
Bitrix\Main\IO\File\__construct
__construct($path, $siteId=null)
Определения
file.php:13
Bitrix\Main\IO\File\$filePointer
$filePointer
Определения
file.php:11
Bitrix\Main\IO\File\readFile
readFile()
Определения
file.php:204
Bitrix\Main\IO\File\markWritable
markWritable()
Определения
file.php:214
Bitrix\Main\IO\File\REWRITE
const REWRITE
Определения
file.php:7
Bitrix\Main\IO\File\isExists
isExists()
Определения
file.php:50
Bitrix\Main\IO\FileNotFoundException
Определения
filenotfoundexception.php:6
Bitrix\Main\IO\FileNotOpenedException
Определения
filenotopenedexception.php:6
Bitrix\Main\IO\FileOpenException
Определения
fileopenexception.php:6
Bitrix\Main\IO\FileStreamOpenMode\READ
const READ
Определения
ifilestream.php:11
Bitrix\Main\IO\FileSystemEntry\$path
$path
Определения
filesystementry.php:9
Bitrix\Main\IO\FileSystemEntry\getPath
getPath()
Определения
filesystementry.php:80
Bitrix\Main\IO\FileSystemEntry\$siteId
$siteId
Определения
filesystementry.php:12
Bitrix\Main\IO\FileSystemEntry\getPhysicalPath
getPhysicalPath()
Определения
filesystementry.php:142
Bitrix\Main\IO\FileSystemEntry\getDirectory
getDirectory()
Определения
filesystementry.php:85
$f
$f
Определения
component_props.php:52
$data
$data['IS_AVAILABLE']
Определения
.description.php:13
$res
$res
Определения
filter_act.php:7
$p
$p
Определения
group_list_element_edit.php:23
Bitrix\Main\IO\IFileStream
Определения
ifilestream.php:5
Bitrix\Main\File
Определения
Image.php:9
$dir
$dir
Определения
quickway.php:303
$contentType
$contentType
Определения
quickway.php:301
bitrix
modules
main
lib
io
file.php
Создано системой
1.14.0