Welcome Guest, Not a member yet? Register   Sign In
get_dir_file_info issue
#1

[eluser]Блум[/eluser]
In the manual is written that get_dir_file_info('path/to/directory/') returns
Quote:..the specified directory and builds an array containing the filenames, filesize, dates, and permissions. Any sub-folders contained within the specified path are read as well.
The problem is that in fact it doensn't read the sub-folders in the specified path for me.. only the files are listed.
Does anyone know something about it?

Thanks
#2

[eluser]evolve08[/eluser]
Works as intended for me, just tested.
#3

[eluser]Блум[/eluser]
This is a simplified example with testing get_dir_file_info() and opendir():
Code:
class Foldertest extends Controller {

    private $folder = "data/imageBin/";

    function Foldertest () {
        parent::Controller();
        
        $this->load->helper('file');
    }
    
    function index() {
        $dirListArray = get_dir_file_info($this->folder);
        echo "Testing get_dir_file_info:\n";
        print_r($dirListArray);
        echo "\n\n\n";
        
        
        echo "Testing opendir:\n";
        $dirListArray = array();
        if ($handle = opendir($this->folder)) {
            while (false !== ($file = readdir($handle))) {
                if ($file != "." && $file != "..") {
                    if (is_dir($this->folder.$file)) $dirListArray[$i]['name'] = "+".$file;
                    else $dirListArray[$i]['name'] = $file;
                }
                $i++;
            }
        }
        print_r($dirListArray);
        echo "\n\n\n";
        
    }
}

And here is the result:
Quote:Testing get_dir_file_info:
Array
(
[IMG_8047.JPG] => Array
(
[name] => IMG_8047.JPG
[server_path] => /home/blum/web_service/inp/data/imageBin/IMG_8047.JPG
[size] => 212638
[date] => 1213602408
[relative_path] => data/imageBin/
)

[IMG_8051.JPG] => Array
(
[name] => IMG_8051.JPG
[server_path] => /home/blum/web_service/inp/data/imageBin/IMG_8051.JPG
[size] => 196861
[date] => 1213611361
[relative_path] => data/imageBin/
)

)



Testing opendir:
Array
(
[] => Array
(
[name] => +bbbbb
)

[1] => Array
(
[name] => +cccccccc
)

[3] => Array
(
[name] => +nnnnnn
)

[5] => Array
(
[name] => +aaaaaaaa
)

[6] => Array
(
[name] => IMG_8047.JPG
)

[7] => Array
(
[name] => IMG_8051.JPG
)

)

Obviously the folders in the first case are not listed, in the case with opendir the folders are properly listed (with "+" at the front)..
Is there something wrong with my code..?

Thanks
#4

[eluser]CI Samson[/eluser]
I have the same issue with get_dir_file_info. Subfolder are not read. It is maybe because the get_dir_file_info call inside the function at line 238 is not assigned to any variable ??
#5

[eluser]Unknown[/eluser]
same problem here...
i changed line 238 to:

$_filedata[$file] = get_dir_file_info($source_dir.$file.DIRECTORY_SEPARATOR, $include_path, TRUE);

did not test a lot but could work...
#6

[eluser]roj[/eluser]
Did this get resolved?
#7

[eluser]roj[/eluser]
It might not help with this specific issue but somehow I missed the directory helper which is all I needed.
#8

[eluser]mrtopher[/eluser]
I'm having the same issue here with the get_dir_file_info() function. It only returns a listing of the files in the folder and not the directories inside.

Looking at line 238 in the helper file... it's the beginning of a while loop.

Code:
while (FALSE !== ($file = readdir($fp)))

The code might have changed since version 1.7.0. Does anyone have a solution to this problem?

The directory helper won't help me much because I want the extra file info. returned by the get_dir_file_info function and you don't get that when using the directory helper.
#9

[eluser]dprock[/eluser]
I've written a "MY_file_helper.php" to address this issue.

PM me if you want it.
#10

[eluser]Derek Jones[/eluser]
The $_filedata array just needed to be declared as static, though it should be noted that the structure is a flat array, not a multidimensional array of the directory structure.




Theme © iAndrew 2016 - Forum software by © MyBB