class File

A File handling class

Methods

static  string
getExt( string $file)

Gets the extension of a file name

static  string
stripExt( string $file)

Strips the last extension off of a file name

static  string
makeSafe( string $file)

Makes file name safe to use

static  boolean
copy( string $src, string $dest, string $path = null, boolean $use_streams = false)

Copies a file

static  boolean
delete( mixed $file)

Delete a file or array of files

static  boolean
move( string $src, string $dest, string $path = '', boolean $use_streams = false)

Moves a file

static  mixed
read( string $filename, boolean $incpath = false, integer $amount, integer $chunksize = 8192, integer $offset)

Read the contents of a file

static  boolean
write( string $file, string $buffer, boolean $use_streams = false)

Write contents to a file

static  boolean
append( string $file, string $buffer, boolean $use_streams = false)

Append contents to a file

static  boolean
upload( string $src, string $dest, boolean $use_streams = false, boolean $allow_unsafe = false, boolean $safeFileOptions = array())

Moves an uploaded file to a destination folder

static  boolean
exists( string $file)

Wrapper for the standard file_exists function

static  string
getName( string $file)

Returns the name, without any path.

Details

static string getExt( string $file)

Gets the extension of a file name

Parameters

string $file The file name

Return Value

string The file extension

static string stripExt( 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

static string makeSafe( string $file)

Makes file name safe to use

Parameters

string $file The name of the file [not full path]

Return Value

string The sanitised string

static boolean copy( string $src, string $dest, string $path = null, boolean $use_streams = false)

Copies a file

Parameters

string $src The path to the source file
string $dest The path to the destination file
string $path An optional base path to prefix to the file names
boolean $use_streams True to use streams

Return Value

boolean True on success

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

static boolean move( string $src, string $dest, string $path = '', boolean $use_streams = false)

Moves a file

Parameters

string $src The path to the source file
string $dest The path to the destination file
string $path An optional base path to prefix to the file names
boolean $use_streams True to use streams

Return Value

boolean True on success

static mixed read( string $filename, boolean $incpath = false, integer $amount, integer $chunksize = 8192, integer $offset)

Read the contents of a file

Parameters

string $filename The full file path
boolean $incpath Use include path
integer $amount Amount of file to read
integer $chunksize Size of chunks to read
integer $offset Offset of the file

Return Value

mixed Returns file contents or boolean False if failed

static boolean write( string $file, string $buffer, boolean $use_streams = false)

Write contents to a file

Parameters

string $file The full file path
string $buffer The buffer to write
boolean $use_streams Use streams

Return Value

boolean True on success

static boolean append( string $file, string $buffer, boolean $use_streams = false)

Append contents to a file

Parameters

string $file The full file path
string $buffer The buffer to write
boolean $use_streams Use streams

Return Value

boolean True on success

static boolean upload( string $src, string $dest, boolean $use_streams = false, boolean $allow_unsafe = false, boolean $safeFileOptions = array())

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
boolean $use_streams True to use streams
boolean $allow_unsafe Allow the upload of unsafe files
boolean $safeFileOptions Options to \JFilterInput::isSafeFile

Return Value

boolean True on success

static boolean exists( string $file)

Wrapper for the standard file_exists function

Parameters

string $file File path

Return Value

boolean True if path is a file

static string getName( string $file)

Returns the name, without any path.

Parameters

string $file File path

Return Value

string filename