Documentation

File extends Node
in package
implements JsonSerializable

Class for handling files.

Table of Contents

Interfaces

JsonSerializable

Constants

MODE_APPEND  = "ab9"
Append mode
MODE_CREATEWRITE  = "wb9"
Create mode for writing
MODE_READ  = "rb9"
Read mode
MODE_WRITE  = "wb9"
Write mode

Properties

$access  : Security
Access rights
$attr_created  : int
$attr_lastaccess  : int
$attr_modified  : int
$attributes  : Attributes
Attributes
$binary  : string
$content  : string
$directory  : Directory
$dotfile  : bool
$exists  : bool
$extension  : string
$filename  : string
$mimetype  : string
$name  : string
$path  : string
$size  : int
$access  : Security
Access rights
$attributes  : Attributes
Attributes
$_size  : int
Size of the file in bytes.
$info  : array<string|int, mixed>
File path information.

Methods

__construct()  : mixed
Constructor.
__get()  : mixed
Getter.
__set()  : void
Setter
Append()  : void
Appends data to a file.
Copy()  : void
Copies a file.
CopyTo()  : void
Copies the file to another location.
Create()  : FileStream
Creates a file and returns its stream.
Delete()  : bool
Deletes a file.
Exists()  : bool
Checks if a file exists.
IsDirectory()  : bool
Checks if the given path is a directory.
IsEmpty()  : bool
Checks if a file is empty.
jsonSerialize()  : array<string|int, mixed>
Implements the JsonSerializable interface.
Link()  : mixed
Creates a symbolic link.
Move()  : void
Moves a file.
MoveTo()  : void
Moves the file to another location.
Open()  : FileStream|null
Returns a file stream.
Read()  : string|null
Reads the content of a file.
ToArray()  : array<string|int, mixed>
Returns file data as an array.
ToString()  : string
Retrieves the filename.
Write()  : void
Writes data to a file.
getAttributesObject()  : Attributes
Load attribute data.
getSecurityObject()  : Security
Load access rights data.

Constants

MODE_APPEND

Append mode

public mixed MODE_APPEND = "ab9"

MODE_CREATEWRITE

Create mode for writing

public mixed MODE_CREATEWRITE = "wb9"

MODE_READ

Read mode

public mixed MODE_READ = "rb9"

MODE_WRITE

Write mode

public mixed MODE_WRITE = "wb9"

Properties

$access read-only

Access rights

public Security $access

Access rights of the file.

$attr_created read-only

public int $attr_created

Timestamp of file creation.

$attr_lastaccess read-only

public int $attr_lastaccess

Timestamp of last access.

$attr_modified read-only

public int $attr_modified

Timestamp of last modification.

$attributes read-only

Attributes

public Attributes $attributes

Attributes of the file.

$binary read-only

public string $binary

Binary content of the file.

$content read-only

public string $content

Content of the file.

$directory read-only

public Directory $directory

Directory containing the file.

$dotfile read-only

public bool $dotfile

Indicates if the file is a dot file.

$exists read-only

public bool $exists

Indicates if the file exists.

$extension read-only

public string $extension

Extension of the file.

$filename read-only

public string $filename

Filename.

$mimetype read-only

public string $mimetype

Mime type of the file.

$name read-only

public string $name

Name of the file.

$path read-only

public string $path

Full path of the file.

$size read-only

public int $size

Size of the file in bytes.

$_size

Size of the file in bytes.

private int $_size = 0

$info

File path information.

private array<string|int, mixed> $info

Methods

__construct()

Constructor.

public __construct(string $path) : mixed
Parameters
$path : string

The path to the file.

Tags
throws
Exception

if the provided path is not a file path.

__get()

Getter.

public __get(string $property) : mixed
Parameters
$property : string

Property name.

__set()

Setter

public __set(string $property, mixed $value) : void
Parameters
$property : string

Property

$value : mixed

Value

Append()

Appends data to a file.

public static Append(string $path, string $content[, bool $recursive = false ][, string $mode = '777' ]) : void
Parameters
$path : string

The path to the file.

$content : string

The content to be appended.

$recursive : bool = false

Whether to create directories along the path if they don't exist. Defaults to false.

$mode : string = '777'

The mode for creating the file and directories. Defaults to '777'.

Copy()

Copies a file.

public static Copy(string $from, string $to) : void
Parameters
$from : string

The source file path.

$to : string

The destination file path.

CopyTo()

Copies the file to another location.

public CopyTo(string $path) : void
Parameters
$path : string

The destination path.

Create()

Creates a file and returns its stream.

public static Create(string $path[, bool $recursive = true ][, string $mode = '777' ]) : FileStream
Parameters
$path : string

The path to the file.

$recursive : bool = true

If true, creates directories along the path if they don't exist.

$mode : string = '777'

The mode for creating the file and directories, default is '777'.

Return values
FileStream

Returns FileStream object for the created file.

Delete()

Deletes a file.

public static Delete(string $path) : bool
Parameters
$path : string

The path to the file.

Return values
bool

Returns true if the file was successfully deleted, false otherwise.

Exists()

Checks if a file exists.

public static Exists(string $path) : bool
Parameters
$path : string

The path to the file.

Return values
bool

Returns true if the file exists, false otherwise.

IsDirectory()

Checks if the given path is a directory.

public static IsDirectory(string $path) : bool
Parameters
$path : string

The path to check.

Return values
bool

Returns true if the path is a directory, false otherwise.

IsEmpty()

Checks if a file is empty.

public static IsEmpty(string $path) : bool
Parameters
$path : string

The path to the file.

Return values
bool

Returns true if the file is empty or doesn't exist, false otherwise.

jsonSerialize()

Implements the JsonSerializable interface.

public jsonSerialize() : array<string|int, mixed>
Return values
array<string|int, mixed>

Returns the array representation of the object.

Creates a symbolic link.

public static Link(string $sourcePath, string $destPath[, bool $recursive = true ][, string $mode = '777' ]) : mixed
Parameters
$sourcePath : string

The path to the source file or directory.

$destPath : string

The path to the destination where the link will be created.

$recursive : bool = true

Whether to create parent directories if they don't exist. Defaults to true.

$mode : string = '777'

The mode for the parent directory if it needs to be created. Defaults to '777'.

Move()

Moves a file.

public static Move(string $from, string $to) : void
Parameters
$from : string

The source file path.

$to : string

The destination file path.

MoveTo()

Moves the file to another location.

public MoveTo(string $path) : void
Parameters
$path : string

The destination path.

Open()

Returns a file stream.

public static Open(string $path) : FileStream|null
Parameters
$path : string

The path to the file.

Return values
FileStream|null

Returns FileStream object if file exists, otherwise returns null.

Read()

Reads the content of a file.

public static Read(string $path) : string|null
Parameters
$path : string

The path to the file.

Return values
string|null

The content of the file or null if the file does not exist.

ToArray()

Returns file data as an array.

public ToArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

Returns an array containing file data.

ToString()

Retrieves the filename.

public ToString() : string
Return values
string

Write()

Writes data to a file.

public static Write(string $path, string $content[, bool $recursive = false ][, string $mode = '777' ]) : void
Parameters
$path : string

The path to the file.

$content : string

The content to be written.

$recursive : bool = false

Whether to create directories along the path if they don't exist. Defaults to false.

$mode : string = '777'

The mode for creating the file and directories. Defaults to '777'.

Tags
throws
ErrorException

if writing to the file fails.

getSecurityObject()

Load access rights data.

protected getSecurityObject() : Security
Return values
Security

        
On this page

Search results