File Class

package Fuel
subpackage Core
category Core

 Methods

_init()

_init() 

Append to a file

append(string $basepath, string $name, string $contents, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$basepath

string

directory where to write the file

$name

string

filename

$contents

string

contents of file

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\InvalidPathException
\FileAccessException
\OutsideAreaException

Returns

bool

Close file resource & unlock

close_file(resource $resource, string | \Fuel\Core\File_Area | null $area) 

Parameters

$resource

resource

open file resource

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Copy file

copy(string $path, string $new_path, string | \Fuel\Core\File_Area | null $source_area, string | \Fuel\Core\File_Area | null $target_area) : bool

Parameters

$path

string

path path to file to copy

$new_path

string

new_path new base directory (full path)

$source_area

string\Fuel\Core\File_Areanull

source_area source path file area name, object or null for non-specific

$target_area

string\Fuel\Core\File_Areanull

target_area target path file area name, object or null for non-specific. Defaults to source_area if not set.

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

bool

Copy directory

copy_dir(string $path, string $new_path, string | \Fuel\Core\File_Area | null $source_area, string | \Fuel\Core\File_Area | null $target_area) 

Parameters

$path

string

path to directory which contents will be copied

$new_path

string

new base directory (full path)

$source_area

string\Fuel\Core\File_Areanull

source path file area name, object or null for non-specific

$target_area

string\Fuel\Core\File_Areanull

target path file area name, object or null for non-specific. Defaults to source_area if not set.

Exceptions

\FileAccessException when something went wrong
\InvalidPathException
\OutsideAreaException

Create a file

create(string $basepath, string $name, null $contents, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$basepath

string

directory where to create file

$name

string

filename

$contents

null

contents of file

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

bool

Create an empty directory

create_dir(string $basepath, string $name, int $chmod, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$basepath

string

directory where to create new dir

$name

string

dirname

$chmod

int

(octal) file permissions

$area

string\Fuel\Core\File_Areanull

file area name, object or null for non-specific

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

bool

Delete file

delete(string $path, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$path

string

path to file to delete

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

bool

Delete directory

delete_dir(string $path, bool $recursive, bool $delete_top, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$path

string

path to directory to delete

$recursive

bool

whether to also delete contents of subdirectories

$delete_top

bool

whether to delete the parent dir itself when empty

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

bool

Download a file

download(string $path, string | null $name, string | null $mime, string | \Fuel\Core\File_Area | null $area, bool $delete, string $disposition) 

Parameters

$path

string

file path

$name

stringnull

custom name for the file to be downloaded

$mime

stringnull

custom mime type or null for file mime type

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

$delete

bool

delete the file after download when true

$disposition

string

disposition, must be 'attachment' or 'inline'

Check for file existence

exists(string $path, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$path

string

path to file to check

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Returns

bool

Get detailed information about a file

file_info(string $path, string | \Fuel\Core\File_Area | null $area) : array

Parameters

$path

string

file path

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

array

forge()

forge(array $config) 

Parameters

$config

File & directory objects factory

get(string $path, array $config, string | \Fuel\Core\File_Area | null $area) : \Fuel\Core\File_Handler_File

Parameters

$path

string

path to the file or directory

$config

array

configuration items

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Returns

Get the octal permissions for a file or directory

get_permissions(string $path, string | \Fuel\Core\File_Area | null $area) : string

Parameters

$path

string

path to the file or directory

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

stringoctal file permissions

Get a file's size.

get_size(string $path, mixed $area) : int

Parameters

$path

string

path to the file or directory

$area

mixed

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

intthe file's size in bytes

Get a file's or directory's created or modified timestamp.

get_time(string $path, string $type, string | \Fuel\Core\File_Area | null $area) : int

Parameters

$path

string

path to the file or directory

$type

string

modified or created

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

intUnix Timestamp

Get the url.

get_url(string $path, array $config, null $area) : bool

Parameters

$path

string

$config

array

$area

null

Returns

bool

Instance

instance(string | \Fuel\Core\File_Area | null $area) : \Fuel\Core\File_Area

Parameters

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Returns

Open and lock file

open_file(resource | string $path, \Fuel\Core\constant | bool $lock, string | \Fuel\Core\File_Area | null $area) : bool | resource

Parameters

$path

resourcestring

file resource or path

$lock

\Fuel\Core\constantbool

either valid lock constant or true=LOCK_EX / false=LOCK_UN

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\OutsideAreaException

Returns

boolresource

Read file

read(string $path, bool $as_string, string | \Fuel\Core\File_Area | null $area) : \Fuel\Core\IO | string

Parameters

$path

string

file to read

$as_string

bool

whether to use readfile() or file_get_contents()

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

\Fuel\Core\IOstringfile contents

Read directory

read_dir(string $path, int $depth, Array | null $filter, string | \Fuel\Core\File_Area | null $area) : array

Parameters

$path

string

directory to read

$depth

int

depth to recurse directory, 1 is only current and 0 or smaller is unlimited

$filter

Arraynull

array of partial regexps or non-array for default

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\FileAccessException
\InvalidPathException
\OutsideAreaException

Returns

array

Rename directory or file

rename(string $path, string $new_path, string | \Fuel\Core\File_Area | null $source_area, string | \Fuel\Core\File_Area | null $target_area) : bool

Parameters

$path

string

path to file or directory to rename

$new_path

string

new path (full path, can also cause move)

$source_area

string\Fuel\Core\File_Areanull

source path file area name, object or null for non-specific

$target_area

string\Fuel\Core\File_Areanull

target path file area name, object or null for non-specific. Defaults to source_area if not set.

Exceptions

\FileAccessException
\OutsideAreaException

Returns

bool

Alias for rename(), not needed but consistent with other methods

rename_dir(string $path, string $new_path, string | \Fuel\Core\File_Area | null $source_area, string | \Fuel\Core\File_Area | null $target_area) : bool

Parameters

$path

string

path to directory to rename

$new_path

string

new path (full path, can also cause move)

$source_area

string\Fuel\Core\File_Areanull

source path file area name, object or null for non-specific

$target_area

string\Fuel\Core\File_Areanull

target path file area name, object or null for non-specific. Defaults to source_area if not set.

Exceptions

\FileAccessException
\OutsideAreaException

Returns

bool

Update a file

update(string $basepath, string $name, string $contents, string | \Fuel\Core\File_Area | null $area) : bool

Parameters

$basepath

string

directory where to write the file

$name

string

filename

$contents

string

contents of file

$area

string\Fuel\Core\File_Areanull

file area name, object or null for base area

Exceptions

\InvalidPathException
\FileAccessException
\OutsideAreaException

Returns

bool

 Properties

 

<p>loaded area's</p>

$areas : array