File

A File handling class

since

1.7.0

package

Application

Methods

append

Append contents to a file

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

3.6.0

Arguments

file

stringThe full file path

buffer

stringThe buffer to write

useStreams

boolUse streams

Response

boolTrue 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() : bool
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

boolTRUE 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, bool useStreams = false) : bool
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

boolTrue to use streams

Response

boolTrue on success

delete

Delete a file or array of files

delete(mixed file) : bool
static
since

1.7.0

Arguments

file

mixedThe file name or an array of file names

Response

boolTrue on success

exists

Wrapper for the standard file_exists function

exists(string file) : bool
static
since

1.7.0

Arguments

file

stringFile path

Response

boolTrue 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, bool force = true) : bool
static
since

4.0.1

Arguments

filepath

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

force

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

Response

boolTRUE 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 = '', bool useStreams = false) : bool
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

boolTrue to use streams

Response

boolTrue 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, bool useStreams = false, bool allowUnsafe = false, array safeFileOptions = array()) : bool
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

boolTrue to use streams

allowUnsafe

boolAllow the upload of unsafe files

safeFileOptions

arrayOptions to InputFilter::isSafeFile

Response

boolTrue on success

write

Write contents to a file

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

1.7.0

Arguments

file

stringThe full file path

buffer

stringThe buffer to write

useStreams

boolUse streams

Response

boolTrue on success

Properties

canFlushFileCache

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

static
since

4.0.1

Type(s)

bool