Skip to content

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!

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments