How To Get All Files Of Directory as array in CodeIgniter?

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

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.

0 0 vote
Article Rating
Notify of
1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
Bahut Ghamgeen
Bahut Ghamgeen
5 years ago

the example code isn’t available. Protection Status
Would love your thoughts, please comment.x