Monday, February 17, 2014

How To Get All Files Of Directory-Subdirectories as Dropdown List Using Codeigniter?

I have a folders inside a view directory. Some of the folders contains files and some other contains another subfolder with its file. What I want is list list all the files of folders and subfolders inside a view directory.

I found a the Directory Helper in Codeigniter. It contains functions that assist in working with directories. I used following function (recursive method) to create a drop-down list with files inside a view directory.
$this->load->helper('directory'); //load directory helper
$dir = APPPATH. "views/your_folder/";
$map = directory_map($dir);
echo "<select name='yourfiles'>";

function show_dir_files($in,$path) { foreach ($in as $k => $v) { if (!is_array($v)) {?> <option><?php echo $path,$v ?></option> <?php } else { print_dir($v,$path.$k.DIRECTORY_SEPARATOR); } } } show_dir_files($map,''); // call the function echo "</select>"; ?>

No comments:

Post a Comment