CodeIgniter v4.5 API

filesystem_helper.php

This file is part of CodeIgniter 4 framework.

(c) CodeIgniter Foundation admin@codeigniter.com

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Table of Contents

Functions

directory_map()  : array<string|int, mixed>
Create a Directory Map
directory_mirror()  : void
Recursively copies the files and directories of the origin directory into the target directory, i.e. "mirror" its contents.
write_file()  : bool
Write File
delete_files()  : bool
Delete Files
get_filenames()  : array<string|int, mixed>
Get Filenames
get_dir_file_info()  : array<string|int, mixed>
Get Directory File Information
get_file_info()  : array<string|int, mixed>|null
Get File Info
symbolic_permissions()  : string
Symbolic Permissions
octal_permissions()  : string
Octal Permissions
same_file()  : bool
Checks if two files both exist and have identical hashes
set_realpath()  : string
Set Realpath

Functions

directory_map()

Create a Directory Map

directory_map(string $sourceDir[, int $directoryDepth = 0 ][, bool $hidden = false ]) : array<string|int, mixed>

Reads the specified directory and builds an array representation of it. Sub-folders contained with the directory will be mapped as well.

Parameters
$sourceDir : string

Path to source

$directoryDepth : int = 0

Depth of directories to traverse (0 = fully recursive, 1 = current dir, etc)

$hidden : bool = false

Whether to show hidden files

Return values
array<string|int, mixed>

directory_mirror()

Recursively copies the files and directories of the origin directory into the target directory, i.e. "mirror" its contents.

directory_mirror(string $originDir, string $targetDir[, bool $overwrite = true ]) : void
Parameters
$originDir : string
$targetDir : string
$overwrite : bool = true

Whether individual files overwrite on collision

Tags
throws
InvalidArgumentException

write_file()

Write File

write_file(string $path, string $data[, string $mode = 'wb' ]) : bool

Writes data to the file specified in the path. Creates a new file if non-existent.

Parameters
$path : string

File path

$data : string

Data to write

$mode : string = 'wb'

fopen() mode (default: 'wb')

Return values
bool

delete_files()

Delete Files

delete_files(string $path[, bool $delDir = false ][, bool $htdocs = false ][, bool $hidden = false ]) : bool

Deletes all files contained in the supplied directory path. Files must be writable or owned by the system in order to be deleted. If the second parameter is set to true, any directories contained within the supplied base directory will be nuked as well.

Parameters
$path : string

File path

$delDir : bool = false

Whether to delete any directories found in the path

$htdocs : bool = false

Whether to skip deleting .htaccess and index page files

$hidden : bool = false

Whether to include hidden files (files beginning with a period)

Return values
bool

get_filenames()

Get Filenames

get_filenames(string $sourceDir[, bool|null $includePath = false ][, bool $hidden = false ][, bool $includeDir = true ]) : array<string|int, mixed>

Reads the specified directory and builds an array containing the filenames. Any sub-folders contained within the specified path are read as well.

Parameters
$sourceDir : string

Path to source

$includePath : bool|null = false

Whether to include the path as part of the filename; false for no path, null for a relative path, true for full path

$hidden : bool = false

Whether to include hidden files (files beginning with a period)

$includeDir : bool = true

Whether to include directories

Return values
array<string|int, mixed>

get_dir_file_info()

Get Directory File Information

get_dir_file_info(string $sourceDir[, bool $topLevelOnly = true ][, bool $recursion = false ]) : array<string|int, mixed>

Reads the specified directory and builds an array containing the filenames, filesize, dates, and permissions

Any sub-folders contained within the specified path are read as well.

Parameters
$sourceDir : string

Path to source

$topLevelOnly : bool = true

Look only at the top level directory specified?

$recursion : bool = false

Internal variable to determine recursion status - do not use in calls

Return values
array<string|int, mixed>

get_file_info()

Get File Info

get_file_info(string $file[, array<string|int, mixed>|string $returnedValues = ['name', 'server_path', 'size', 'date'] ]) : array<string|int, mixed>|null

Given a file and path, returns the name, path, size, date modified Second parameter allows you to explicitly declare what information you want returned Options are: name, server_path, size, date, readable, writable, executable, fileperms Returns false if the file cannot be found.

Parameters
$file : string

Path to file

$returnedValues : array<string|int, mixed>|string = ['name', 'server_path', 'size', 'date']

Array or comma separated string of information returned

Return values
array<string|int, mixed>|null

symbolic_permissions()

Symbolic Permissions

symbolic_permissions(int $perms) : string

Takes a numeric value representing a file's permissions and returns standard symbolic notation representing that value

Parameters
$perms : int

Permissions

Return values
string

octal_permissions()

Octal Permissions

octal_permissions(int $perms) : string

Takes a numeric value representing a file's permissions and returns a three character string representing the file's octal permissions

Parameters
$perms : int

Permissions

Return values
string

same_file()

Checks if two files both exist and have identical hashes

same_file(string $file1, string $file2) : bool
Parameters
$file1 : string
$file2 : string
Return values
bool

Same or not

set_realpath()

Set Realpath

set_realpath(string $path[, bool $checkExistence = false ]) : string
Parameters
$path : string
$checkExistence : bool = false

Checks to see if the path exists

Return values
string

        
On this page

Search results