Provides functions for dealing with files

 Methods

Changes the file permissions

chmod(string $filename, int $mode) : bool
Static

Parameters

$filename

string

the name and path of the file

$mode

int

the new access mode

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue on success

Copies a file

copy(string $filename, string $destination) : bool
Static

Parameters

$filename

string

the name and path of the file

$destination

string

the destination. Note that existing files get overwritten

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue on success

Creates a new file

create(string $filename, string $content) : bool
Static

Parameters

$filename

string

the name and path of the new file

$content

string

optional content of the new file. Optional.

Returns

booltrue on success. Otherwise false.

Checks if a file exists

exists(string $filename) : bool
Static

Parameters

$filename

string

the name and path of the file

Returns

booltrue if the file exists

Returns the extension of passed filename

getExtension(string $basename) : string
Static

Parameters

$basename

string

Returns

string

Returns an array containing information about the file.

info(string $filename) : array
Static

Currently following elements are in it: 'size' - the file size (in byte) 'atime' - the time the file was last accessed (unix timestamp) 'ctime' - time the file was created (unix timestamp) 'mtime' - time the file was last modified (unix timestamp) 'perms' - permissions of the file represented in 4 octal digits 'extension' - the file extension or '' if there's no extension 'mime' - the mime type of the file

Parameters

$filename

string

the name and path to the file

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

arrayReturns an array containing information about the file

Moves a file

move(string $filename, string $destination) : bool
Static

Parameters

$filename

string

the name of the source file

$destination

string

the destination. Note that the file can also be renamed in the process of moving it

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue on success

Reads bytes from a file

read(string $filename, int $length, int $offset, bool $reverse) : string
Static

Parameters

$filename

string

the name and path of the file

$length

int

the number of bytes to read. Optional.

$offset

int

this will be the first byte which is read. Optional.

$reverse

bool

if true, the function will start from the back of the file. Optional.

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

stringbool success it returns the bytes which have been read. Otherwise false.

Reads a file line by line

readLine(string $filename, int $lines, int $lineoffset) : string
Static

Parameters

$filename

string

the name and path of the file

$lines

int

the number of lines to be read. Optional.

$lineoffset

int

this will be the first line which is read. Optional.

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

stringarray bool one line was read the function will return it. If more than one line was read the function will return an array containing the lines. Otherwise false is returned

Checks if a file is readable for the PHP user

readable(string $filename) : bool
Static

Parameters

$filename

string

the name and path of the file

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue if the file is readable

Deletes a directory and all of its contents.

recursiveRmdir(string $dirname) : bool
Static

Parameters

$dirname

string

the name of the directory which should be deleted

Returns

booltrue on success or false on failure

Removes a file from the filesystem

remove(string $filename) : bool
Static

Parameters

$filename

string

the name and path of the file

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue on success

Renames a file

rename(string $filename, string $new_filename) : bool
Static

Parameters

$filename

string

the name and path of the file

$new_filename

string

the new name of the file

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue on success

Sets the default directory permissions on the given directory.

setDefaultDirPerms(string $pathname) : boolean
Static

Parameters

$pathname

string

the name of the directory

Returns

booleantrue on success or false on failure

Sets the default file permissions on the given file.

setDefaultFilePerms(string $filename) : boolean
Static

Parameters

$filename

string

the name of the file

Returns

booleantrue on success or false on failure

Truncates a file so that it is empty

truncate(string $filename) : bool
Static

Parameters

$filename

string

the name and path of the file

Exceptions

\cInvalidArgumentException if the file with the given filename does not exist

Returns

booltrue on success

Validates the given filename.

validateFilename(string $filename, boolean $notifyAndExitOnFailure) : boolean
Static

Parameters

$filename

string

the filename to validate

$notifyAndExitOnFailure

boolean

if set, function will show a notification and will exit the script

Returns

booleantrue if the given filename is valid, false otherwise

Writes data to a file

write(string $filename, string $content, bool $append) : bool
Static

Parameters

$filename

string

the name and path of the file

$content

string

the data which should be written

$append

bool

if true the data will be appended to the file. Optional.

Returns

booltrue on success, false otherwise

Writes a line to a file (this is similar to cFileHandler::write($filename, $data."\n", $apppend)

writeLine(string $filename, string $content, bool $append) : bool
Static
see $content, $append)

Parameters

$filename

string

the name and path to the file

$content

string

the data of the line

$append

bool

if true the data will be appended to file. Optional.

Returns

booltrue on success, false otherwise

Checks if the file is writable for the PHP user

writeable(string $filename) : bool
Static

Parameters

$filename

string

the name and path of the file

Returns

booltrue if the file can be written