File

A File handling class

since

1.7.0

Methods

append

Append contents to a file

append(string $file, string $buffer, boolean $useStreams = false) : boolean
static
since

3.6.0

Arguments

$file

stringThe full file path

$buffer

stringThe buffer to write

$useStreams

booleanUse streams

Response

booleanTrue on success

canFlushFileCache

First we check if opcache is enabled Then we check if the opcache_invalidate function is available Lastly we check if the host has restricted which scripts can use opcache_invalidate using opcache.restrict_api.

canFlushFileCache() : boolean
static

$_SERVER['SCRIPT_FILENAME'] approximates the origin file's path, but realpath() is necessary because SCRIPT_FILENAME can be a relative path when run from CLI. If the host has this set, check whether the path in opcache.restrict_api matches the beginning of the path of the origin file.

since

4.0.1

Response

booleanTRUE if we can proceed to use opcache_invalidate to flush a file from the OPCache

copy

Copies a file

copy(string $src, string $dest, string $path = null, boolean $useStreams = false) : boolean
static
since

1.7.0

Arguments

$src

stringThe path to the source file

$dest

stringThe path to the destination file

$path

stringAn optional base path to prefix to the file names

$useStreams

booleanTrue to use streams

Response

booleanTrue on success

delete

Delete a file or array of files

delete(mixed $file) : boolean
static
since

1.7.0

Arguments

$file

mixedThe file name or an array of file names

Response

booleanTrue on success

exists

Wrapper for the standard file_exists function

exists(string $file) : boolean
static
since

1.7.0

Arguments

$file

stringFile path

Response

booleanTrue if path is a file

getExt

Gets the extension of a file name

getExt(string $file) : string
static
since

1.7.0

Arguments

$file

stringThe file name

Response

stringThe file extension

invalidateFileCache

Invalidate opcache for a newly written/deleted file immediately, if opcache* functions exist and if this was a PHP file.

invalidateFileCache(string $filepath, boolean $force = true) : boolean
static
since

4.0.1

Arguments

$filepath

stringThe path to the file just written to, to flush from opcache

$force

booleanIf set to true, the script will be invalidated regardless of whether invalidation is necessary

Response

booleanTRUE if the opcode cache for script was invalidated/nothing to invalidate, or FALSE if the opcode cache is disabled or other conditions returning FALSE from opcache_invalidate (like file not found).

makeSafe

Makes file name safe to use

makeSafe(string $file) : string
static
since

1.7.0

Arguments

$file

stringThe name of the file [not full path]

Response

stringThe sanitised string

move

Moves a file

move(string $src, string $dest, string $path = '', boolean $useStreams = false) : boolean
static
since

1.7.0

Arguments

$src

stringThe path to the source file

$dest

stringThe path to the destination file

$path

stringAn optional base path to prefix to the file names

$useStreams

booleanTrue to use streams

Response

booleanTrue on success

stripExt

Strips the last extension off of a file name

stripExt(string $file) : string
static
since

1.7.0

Arguments

$file

stringThe file name

Response

stringThe file name without the extension

upload

Moves an uploaded file to a destination folder

upload(string $src, string $dest, boolean $useStreams = false, boolean $allowUnsafe = false, array $safeFileOptions = array()) : boolean
static
since

1.7.0

Arguments

$src

stringThe name of the php (temporary) uploaded file

$dest

stringThe path (including filename) to move the uploaded file to

$useStreams

booleanTrue to use streams

$allowUnsafe

booleanAllow the upload of unsafe files

$safeFileOptions

arrayOptions to InputFilter::isSafeFile

Response

booleanTrue on success

write

Write contents to a file

write(string $file, string $buffer, boolean $useStreams = false) : boolean
static
since

1.7.0

Arguments

$file

stringThe full file path

$buffer

stringThe buffer to write

$useStreams

booleanUse streams

Response

booleanTrue on success

Properties

canFlushFileCache

true if OPCache enabled, and we have permission to invalidate files

static
since

4.0.1

Type(s)

boolean