Documentation

File constructor

resource public
\Bitrix\Main\IO\File::__construct(
 string $path,
 $siteId = null
);

Non-static method is called when creating a class instance, allowing performing specific actions within it when creating an object.

Parameters

ParameterDescriptionVersion
$pathFull file path.
$siteIdSite ID.

Examples

Create a classic instance:

$file=new \Bitrix\Main\IO\File($path, $siteId = null);

Now the file path passed to the constructor can be handled as follows:

Open the file. Parameter specifies type of access, requested from stream. This parameter is similar to the function php fopen.

$file->open($mode)

Check, if it is exist.

$file->isExists()

Write data into file similar to the static method putFileContents.

$file->putContents($data, $flags=self::REWRITE)

Get file size.

$file->getSize()

Verify, if file is available for writing.

$file->isWritable()

Verify, if file is available for reading.

$file->isReadable()

Read file and write it into output buffer. Get number of bytes, read from file.

$file->readFile()

Get date for file creation.

$file->getCreationTime()

Get time of the last access to file.

$file->getLastAccessTime()

Get time of the last file update.

$file->getModificationTime()

Sets access permissions for the file.

$file->markWritable()

Get access permissions to file.

$file->getPermissions()

Delete the file.

$file->delete()

Get type of file content.

$file->getContentType()


© «Bitrix24», 2001-2024
Up