Today i want to show you how to use codeigniter directory helper for getting list of files as array from given directory and its sub directory.
CI’s directory helper is very easy to use, which contains functions that assist in working with directories.
How to use
In order to use directory helper functions we must load the helper , then only the functions are available.
How to Load helper
We can load helper in two different methods both methods as it’s own advantages. Depending on the requremnt we have to pick the correct method.
1.Autoloading : we can autoloader helpers by adding helper name in the( $autoload[‘helper’]= array(‘helperName’)) array which is located at aplication/config/autoload.php.
By auto loading we can assess helper any were in the application. this is not recommend if you are using helper in one controller or in one controller action.
2. Manual Loading : we load helper by using $this->load->helper(‘helper_name’). we can place this line in controller method(action) or we can load this in controller constructor. By loading it in constructor it will available in controller class methods.
Here is the example for getting all Files Of Directory as array
1 |
Thats it, Happy Coding!
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.
the example code isn’t available.