class File (View source)

A File handling class

Methods

static string
stripExtension(string $file)

Strips the last extension off of a file name

static string
getExtension(string $file)

getExtension

static string
getFilename(string $path)

Get file name from a path.

static string
makeSafe(string $file, array $stripChars = array('#^\\.#'))

Makes the file name safe to use

static boolean
copy(string $src, string $dest, bool $force = false)

Copies a file

static boolean
delete(mixed $file)

Delete a file or array of files

static boolean
move(string $src, string $dest, bool $force = false)

Moves a file

static boolean
write(string $file, string $buffer)

Write contents to a file

static boolean
upload(string $src, string $dest)

Moves an uploaded file to a destination folder

Details

at line line 29
static string stripExtension(string $file)

Strips the last extension off of a file name

Parameters

string $file The file name

Return Value

string The file name without the extension

at line line 43
static string getExtension(string $file)

getExtension

Parameters

string $file The file path to get extension.

Return Value

string The ext of file path.

at line line 57
static string getFilename(string $path)

Get file name from a path.

Parameters

string $path The file path to get basename.

Return Value

string The file name.

at line line 81
static string makeSafe(string $file, array $stripChars = array('#^\\.#'))

Makes the file name safe to use

Parameters

string $file The name of the file [not full path]
array $stripChars Array of regex (by default will remove any leading periods)

Return Value

string The sanitised string

at line line 106
static boolean copy(string $src, string $dest, bool $force = false)

Copies a file

Parameters

string $src The path to the source file
string $dest The path to the destination file
bool $force Force copy.

Return Value

boolean True on success

Exceptions

UnexpectedValueException
FilesystemException

at line line 153
static boolean delete(mixed $file)

Delete a file or array of files

Parameters

mixed $file The file name or an array of file names

Return Value

boolean True on success

Exceptions

FilesystemException

at line line 188
static boolean move(string $src, string $dest, bool $force = false)

Moves a file

Parameters

string $src The path to the source file
string $dest The path to the destination file
bool $force Force move it.

Return Value

boolean True on success

Exceptions

FilesystemException

at line line 236
static boolean write(string $file, string $buffer)

Write contents to a file

Parameters

string $file The full file path
string $buffer The buffer to write

Return Value

boolean True on success

Exceptions

FilesystemException

at line line 263
static boolean upload(string $src, string $dest)

Moves an uploaded file to a destination folder

Parameters

string $src The name of the php (temporary) uploaded file
string $dest The path (including filename) to move the uploaded file to

Return Value

boolean True on success

Exceptions

FilesystemException