class SplFileInfo implements Stringable (View source)

The SplFileInfo class offers a high-level object oriented interface to information for an individual file.

Methods

__construct(string $filename)

Construct a new SplFileInfo object

string
getPath()

Gets the path without filename

string
getFilename()

Gets the filename

string
getExtension()

Gets the file extension

string
getBasename(string $suffix = '')

Gets the base name of the file

string
getPathname()

Gets the path to the file

int|false
getPerms()

Gets file permissions

int|false
getInode()

Gets the inode for the file

int|false
getSize()

Gets file size

int|false
getOwner()

Gets the owner of the file

int|false
getGroup()

Gets the file group

int|false
getATime()

Gets last access time of the file

int|false
getMTime()

Gets the last modified time

int|false
getCTime()

Gets the inode change time

string|false
getType()

Gets file type

bool
isWritable()

Tells if the entry is writable

bool
isReadable()

Tells if file is readable

bool
isExecutable()

Tells if the file is executable

bool
isFile()

Tells if the object references a regular file

bool
isDir()

Tells if the file is a directory

bool
isLink()

Tells if the file is a link

string|false
getLinkTarget()

Gets the target of a link

string|false
getRealPath()

Gets absolute path to file

getFileInfo(T> $class = null)

Gets an SplFileInfo object for the file

getPathInfo(T> $class = null)

Gets an SplFileInfo object for the path

openFile(string $mode = 'r', bool $useIncludePath = false, resource $context = null)

Gets an SplFileObject object for the file

void
setFileClass(T> $class = SplFileObject::class)

Sets the class name used with SplFileInfo::openFile

void
setInfoClass(T> $class = SplFileInfo::class)

Sets the class used with getFileInfo and getPathInfo

string
__toString()

Returns the path to the file as a string

void
_bad_state_ex()

No description

__wakeup()

No description

array
__debugInfo()

No description

Details

__construct(string $filename)

Since: 5.1.2

Construct a new SplFileInfo object

Parameters

string $filename

string getPath()

Since: 5.1.2

Gets the path without filename

Return Value

string

the path to the file.

string getFilename()

Since: 5.1.2

Gets the filename

Return Value

string

The filename.

string getExtension()

Since: 5.3.6

Gets the file extension

Return Value

string

a string containing the file extension, or an empty string if the file has no extension.

string getBasename(string $suffix = '')

Since: 5.2.2

Gets the base name of the file

Parameters

string $suffix

[optional]

Optional suffix to omit from the base name returned.

Return Value

string

the base name without path information.

string getPathname()

Since: 5.1.2

Gets the path to the file

Return Value

string

The path to the file.

int|false getPerms()

Since: 5.1.2

Gets file permissions

Return Value

int|false

The file permissions on success, or FALSE on failure.

int|false getInode()

Since: 5.1.2

Gets the inode for the file

Return Value

int|false

The inode number for the filesystem object on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getSize()

Since: 5.1.2

Gets file size

Return Value

int|false

The filesize in bytes on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getOwner()

Since: 5.1.2

Gets the owner of the file

Return Value

int|false

The owner id in numerical format on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getGroup()

Since: 5.1.2

Gets the file group

Return Value

int|false

The group id in numerical format on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getATime()

Since: 5.1.2

Gets last access time of the file

Return Value

int|false

The time the file was last accessed on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getMTime()

Since: 5.1.2

Gets the last modified time

Return Value

int|false

The last modified time for the file, in a Unix timestamp on success, or FALSE on failure.

int|false getCTime()

Since: 5.1.2

Gets the inode change time

Return Value

int|false

The last change time, in a Unix timestamp on success, or FALSE on failure.

Exceptions

RuntimeException

string|false getType()

Since: 5.1.2

Gets file type

Return Value

string|false

A string representing the type of the entry. May be one of file, link, dir, block, fifo, char, socket, or unknown, or FALSE on failure. May be one of file, link, or dir

Exceptions

RuntimeException

bool isWritable()

Since: 5.1.2

Tells if the entry is writable

Return Value

bool

true if writable, false otherwise;

bool isReadable()

Since: 5.1.2

Tells if file is readable

Return Value

bool

true if readable, false otherwise.

bool isExecutable()

Since: 5.1.2

Tells if the file is executable

Return Value

bool

true if executable, false otherwise.

bool isFile()

Since: 5.1.2

Tells if the object references a regular file

Return Value

bool

true if the file exists and is a regular file (not a link), false otherwise.

bool isDir()

Since: 5.1.2

Tells if the file is a directory

Return Value

bool

true if a directory, false otherwise.

Since: 5.1.2

Tells if the file is a link

Return Value

bool

true if the file is a link, false otherwise.

string|false getLinkTarget()

Since: 5.2.2

Gets the target of a link

Return Value

string|false

The target of the filesystem link on success, or FALSE on failure.

Exceptions

RuntimeException

string|false getRealPath()

Since: 5.2.2

Gets absolute path to file

Return Value

string|false

the path to the file, or FALSE if the file does not exist.

SplFileInfo getFileInfo(T> $class = null)

Since: 5.1.2

Gets an SplFileInfo object for the file

Parameters

T> $class

[optional]

Name of an SplFileInfo derived class to use.

Return Value

SplFileInfo

An SplFileInfo object created for the file.

SplFileInfo|null getPathInfo(T> $class = null)

Since: 5.1.2

Gets an SplFileInfo object for the path

Parameters

T> $class

[optional]

Name of an SplFileInfo derived class to use.

Return Value

SplFileInfo|null

A SplFileInfo object for the parent path of the file on success, or NULL on failure.

SplFileObject openFile(string $mode = 'r', bool $useIncludePath = false, resource $context = null)

Since: 5.1.2

Gets an SplFileObject object for the file

Parameters

string $mode

[optional]

The mode for opening the file. See the fopen documentation for descriptions of possible modes. The default is read only.

bool $useIncludePath

[optional]

resource $context

[optional]

Return Value

SplFileObject

The opened file as an SplFileObject object.

Exceptions

RuntimeException

void setFileClass(T> $class = SplFileObject::class)

Since: 5.1.2

Sets the class name used with SplFileInfo::openFile

Parameters

T> $class

[optional]

The class name to use when openFile() is called.

Return Value

void

void setInfoClass(T> $class = SplFileInfo::class)

Since: 5.1.2

Sets the class used with getFileInfo and getPathInfo

Parameters

T> $class

[optional]

The class name to use.

Return Value

void

string __toString()

Since: 5.1.2

Returns the path to the file as a string

Return Value

string

Returns string representation of the object that implements this interface (and/or "__toString" magic method).

final void _bad_state_ex()

No description

Return Value

void

__wakeup()

No description

array __debugInfo()

Since: 7.4

No description

Return Value

array