Filesystem Helper
The Directory Helper document contains capacities that help with working with registries.
- Stacking this Helper
- Accessible Functions
Stacking this Helper
This aide is stacked utilizing the accompanying code:
helper('filesystem');
Accessible Functions
The accompanying capacities are accessible:
directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]])
Parameters:
$source_dir (string) – Path to the source catalog
$directory_depth (int) – Depth of catalogs to cross (0 = completely recursive, 1 = current dir, and so on)
$hidden (bool) – Whether to incorporate shrouded registries
Returns:
A variety of documents
Bring type back:
cluster
Models:
$map = directory_map('./mydirectory/');
Note
Ways are quite often comparative with your principle index.php document.
Sub-organizers contained inside the catalog will be mapped too. In the event that you wish to control the recursion profundity, you can do so utilizing the subsequent parameter (whole number). A profundity of 1 will just guide the top level registry:
$map = directory_map('./mydirectory/', 1);
As a matter of course, concealed records won't be remembered for the brought exhibit back. To supersede this conduct, you may set a third parameter to valid (boolean):
$map = directory_map('./mydirectory/', FALSE, TRUE);
Every organizer name will be a cluster file, while its contained documents will be numerically ordered. Here is a case of an ordinary exhibit:
Exhibit (
[libraries] => Array
(
[0] => benchmark.html
[1] => config.html
["database/"] => Array
(
[0] => query_builder.html
[1] => binds.html
[2] => configuration.html
[3] => connecting.html
[4] => examples.html
[5] => fields.html
[6] => index.html
[7] => queries.html
)
[2] => email.html
[3] => file_uploading.html
[4] => image_lib.html
[5] => input.html
[6] => language.html
[7] => loader.html
[8] => pagination.html
[9] => uri.html
)
On the off chance that no outcomes are discovered, this will restore a vacant cluster.
write_file($path, $data[, $mode = 'wb'])
Parameters:
$path (string) – File way
$data (string) – Data to write to document
$mode (string) – fopen() mode
Returns:
Valid if the compose was fruitful, FALSE if there should arise an occurrence of a blunder
Bring type back:
bool
Composes information to the document indicated in the way. On the off chance that the document doesn't exist, at that point the capacity will make it.
Model:
$data = 'Some document information';
in the event that ( ! write_file('./way/to/file.php', $data))
{
reverberation 'Unfit to compose the record';
}
else
{
reverberation 'Document composed!';
}
You can alternatively set the compose mode by means of the third parameter:
write_file('./way/to/file.php', $data, 'r+');
The default mode is 'wb'. If you don't mind see the PHP client control for mode choices.
Note
All together for this capacity to compose information to a record, its authorizations must be set with the end goal that it is writable. On the off chance that the record doesn't as of now exist, at that point the index containing it must be writable.
Note
The way is comparative with your primary site index.php record, NOT your controller or view documents. CodeIgniter utilizes a front controller so ways are constantly comparative with the principle site list.
Note
This capacity obtains an elite lock on the record while keeping in touch with it.
delete_files($path[, $del_dir = FALSE[, $htdocs = FALSE]])
Parameters:
$path (string) – Directory way
$del_dir (bool) – Whether to likewise erase registries
$htdocs (bool) – Whether to skip erasing .htaccess and file page records
Returns:
Valid on progress, FALSE if there should arise an occurrence of a mistake
Bring type back:
bool
Erases ALL records contained in the provided way.
Model:
delete_files('./way/to/registry/');
On the off chance that the subsequent parameter is set to TRUE, any registries contained inside the provided root way will be erased also.
Model:
delete_files('./way/to/index/', TRUE);
Note
The documents must be writable or claimed by the framework so as to be erased.
get_filenames($source_dir[, $include_path = FALSE])
Parameters:
$source_dir (string) – Directory way
$include_path (bool|null) – Whether to incorporate the way as a major aspect of the filename; bogus for no way, invalid for the way comparative with $source_dir, valid for the full way
$hidden (bool) – Whether to incorporate concealed records (documents starting with a period)
Returns:
A variety of record names
Bring type back:
exhibit
Accepts a server way as information and returns an exhibit containing the names of all documents contained inside it. The document way can alternatively be added to the record names by setting the second parameter to 'relative' for relative ways or some other non-void an incentive for a full document way.
Model:
$controllers = get_filenames(APPPATH.'controllers/');
get_dir_file_info($source_dir, $top_level_only)
Parameters:
$source_dir (string) – Directory way
$top_level_only (bool) – Whether to take a gander at the predefined registry (barring sub-registries)
Returns:
A cluster containing data on the provided registry's substance
Bring type back:
cluster
Peruses the predefined index and manufactures an exhibit containing the filenames, filesize, dates, and authorizations. Sub-envelopes contained inside the predefined way are possibly perused whenever constrained by sending the subsequent parameter to FALSE, as this can be a concentrated activity.
Model:
$models_info = get_dir_file_info(APPPATH.'models/');
get_file_info($file[, $returned_values = ['name', 'server_path', 'size', 'date']])
Parameters:
$file (string) – File way
$returned_values (array|string) – What kind of data to come back to be passed as exhibit or comma isolated string
Returns:
An exhibit containing data on the predetermined document or FALSE on disappointment
Bring type back:
exhibit
Given a record and way, returns (alternatively) the name, way, size and date adjusted data properties for a document. Second parameter permits you to expressly pronounce what data you need returned.
Substantial $returned_values alternatives are: name, size, date, clear, writeable, executable and fileperms.
symbolic_permissions($perms)
Parameters:
$perms (int) – Permissions
Returns:
Emblematic consents string
Bring type back:
string
Takes numeric authorizations, (for example, is returned by fileperms()) and returns standard representative documentation of record consents.
reverberation symbolic_permissions(fileperms('./index.php'));/ - rw-r- - r- -
octal_permissions($perms)
Parameters:
$perms (int) – Permissions
Returns:
Octal authorizations string
Bring type back:
string
Takes numeric authorizations, (for example, is returned by fileperms()) and restores a three character octal documentation of record consents.
reverberation octal_permissions(fileperms('./index.php'));/644
set_realpath($path[, $check_existence = FALSE])
Parameters:
$path (string) – Path
$check_existence (bool) – Whether to check if the way really exists
Returns:
A flat out way
Bring type back:
string
This capacity will restore a server way without emblematic connections or relative registry structures. A discretionary second contention will make a mistake be activated if the way can't be settled.
Models:
$file = '/and so forth/php5/apache2/php.ini';
reverberation set_realpath($file);/Prints '/and so forth/php5/apache2/php.ini'
$non_existent_file = '/way/to/non-exist-file.txt';
reverberation set_realpath($non_existent_file, TRUE);/Shows a mistake, as the way can't be settled
reverberation set_realpath($non_existent_file, FALSE);/Prints '/way/to/non-exist-file.txt'
$directory = '/and so forth/php5';
reverberation set_realpath($directory);/Prints '/and so forth/php5/'
$non_existent_directory = '/way/to/no place';
reverberation set_realpath($non_existent_directory, TRUE);/Shows a mistake, as the way can't be settled
reverberation set_realpath($non_existent_directory, FALSE);/Prints '/way/to/no place'