\APIFileHandler

Convenience class for reading, writing and appending to files.

Summary

Methods
Properties
Constants
__construct()
__destruct()
create()
open()
read()
offset()
prepare()
write()
append()
close()
delete()
info()
ext()
name()
safe()
md5()
pwd()
exists()
perms()
size()
writable()
executable()
readable()
owner()
group()
lastAccess()
lastChange()
folder()
$folder
$name
$info
$handle
$lock
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$folder

$folder : 

folder object of the File

Type

$name

$name : 

Filename

Type

$info

$info : 

file info

Type

$handle

$handle : 

Holds the file handler resource if the file is opened

Type

$lock

$lock : 

enable locking for file reading and writing

Type

Methods

__construct()

__construct(  path,   create = false,   mode = 0755) : 

Constructor

Parameters

path

Path to file

create

Create file if it does not exist (if true)

mode

Mode to apply to the folder holding the file

Returns

__destruct()

__destruct() : 

Closes the current file if it is opened

Returns

create()

create() : 

Creates the File.

Returns

Success

open()

open(  mode = r,   force = false) : 

Opens the current file with a given $mode

Parameters

mode

A valid 'fopen' mode string (r|w|a ...)

force

If true then the file will be re-opened even if its already opened, otherwise it won't

Returns

True on success, false on failure

read()

read(bool|string|int  bytes = false,   mode = rb,   force = false) : 

Return the contents of this File as a string.

Parameters

bool|string|int bytes

where to start

mode
force

If true then the file will be re-opened even if its already opened, otherwise it won't

Returns

string on success, false on failure

offset()

offset(  offset = false,   seek = SEEK_SET) : 

Sets or gets the offset for the currently opened file.

Parameters

offset

The $offset in bytes to seek. If set to false then the current offset is returned.

seek

PHP Constant SEEK_SET | SEEK_CUR | SEEK_END determining what the $offset is relative to

Returns

True on success, false on failure (set mode), false on failure or integer offset on success (get mode)

prepare()

prepare(  data) : 

Prepares a ascii string for writing fixes line endings

Parameters

data

Data to prepare for writing.

Returns

write()

write(  data,   mode = w, bool|string  force = false) : 

Write given data to this File.

Parameters

data

Data to write to this File.

mode

Mode of writing. {@link http://php.net/fwrite See fwrite()}.

bool|string force

force the file to open

Returns

Success

append()

append(  data, bool|string  force = false) : 

Append given data string to this File.

Parameters

data

Data to write

bool|string force

force the file to open

Returns

Success

close()

close() : 

Closes the current file if it is opened.

Returns

True if closing was successful or file was already closed, otherwise false

delete()

delete() : 

Deletes the File.

Returns

Success

info()

info() : 

Returns the File extension.

Returns

The File extension

ext()

ext() : 

Returns the File extension.

Returns

The File extension

name()

name() : 

Returns the File name without extension.

Returns

The File name without extension.

safe()

safe(  name = null, null|string  ext = null) : 

makes filename safe for saving

Parameters

name

the name of the file to make safe if different from $this->name

null|string ext

Returns

$ext the extension of the file

md5()

md5(  maxsize = 5) : 

Get md5 Checksum of file with previous check of Filesize

Parameters

maxsize

in MB or true to force

Returns

md5 Checksum {@link http://php.net/md5_file See md5_file()}

pwd()

pwd() : 

Returns the full path of the File.

Returns

Full path to file

exists()

exists() : 

Returns true if the File exists.

Returns

true if it exists, false otherwise

perms()

perms() : 

Returns the "chmod" (permissions) of the File.

Returns

Permissions for the file

size()

size() : 

Returns the Filesize, either in bytes or in human-readable format.

Returns

|int filesize as int or as a human-readable string

writable()

writable() : 

Returns true if the File is writable.

Returns

true if its writable, false otherwise

executable()

executable() : 

Returns true if the File is executable.

Returns

true if its executable, false otherwise

readable()

readable() : 

Returns true if the File is readable.

Returns

true if file is readable, false otherwise

owner()

owner() : 

Returns the File's owner.

Returns

the Fileowner

group()

group() : 

Returns the File group.

Returns

the Filegroup

lastAccess()

lastAccess() : 

Returns last access time.

Returns

timestamp Timestamp of last access time

lastChange()

lastChange() : 

Returns last modified time.

Returns

timestamp Timestamp of last modification

folder()

folder() : \Folder

Returns the current folder.

Returns

\Folder —

Current folder