src/System/Helpersfilesystem_helper.php

CodeIgniter

An open source application development framework for PHP

This content is released under the MIT License (MIT)

Copyright (c) 2014-2019 British Columbia Institute of Technology Copyright (c) 2019 CodeIgniter Foundation

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions

directory_map()

directory_map(string  $source_dir, integer  $directory_depth, boolean  $hidden = false) : array

Create a Directory Map

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

Parameters

string $source_dir

Path to source

integer $directory_depth

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

boolean $hidden

Whether to show hidden files

Returns

array

write_file()

write_file(string  $path, string  $data, string  $mode = 'wb') : boolean

Write File

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

Parameters

string $path

File path

string $data

Data to write

string $mode

fopen() mode (default: 'wb')

Returns

boolean

delete_files()

delete_files(string  $path, boolean  $del_dir = false, boolean  $htdocs = false, integer  $_level) : boolean

Delete Files

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

string $path

File path

boolean $del_dir

Whether to delete any directories found in the path

boolean $htdocs

Whether to skip deleting .htaccess and index page files

integer $_level

Current directory depth level (default: 0; internal use only)

Returns

boolean

get_filenames()

get_filenames(string  $source_dir, boolean  $include_path = false, boolean  $recursion = false) : array

Get Filenames

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

Parameters

string $source_dir

Path to source

boolean $include_path

Whether to include the path as part of the filename

boolean $recursion

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

Returns

array

get_dir_file_info()

get_dir_file_info(string  $source_dir, boolean  $top_level_only = true, boolean  $recursion = false) : array

Get Directory File Information

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

string $source_dir

Path to source

boolean $top_level_only

Look only at the top level directory specified?

boolean $recursion

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

Returns

array

get_file_info()

get_file_info(string  $file, mixed  $returned_values = array('name', 'server_path', 'size', 'date')) : array|null

Get File Info

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

string $file

Path to file

mixed $returned_values

Array or comma separated string of information returned

Returns

array|null

symbolic_permissions()

symbolic_permissions(integer  $perms) : string

Symbolic Permissions

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

Parameters

integer $perms

Permissions

Returns

string

octal_permissions()

octal_permissions(integer  $perms) : string

Octal Permissions

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

Parameters

integer $perms

Permissions

Returns

string

set_realpath()

set_realpath(string  $path, boolean  $check_existence = false) : string

Set Realpath

Parameters

string $path
boolean $check_existence

Checks to see if the path exists

Returns

string