Welcome Guest, Not a member yet? Register   Sign In
File Helper get_file_info() and get_dir_file_info() Bug On Windows Systems
#1

[eluser]BrianDHall[/eluser]
The file helper function get_dir_file_info() does not work properly due to a tiny bug that assumes a / when Windows of course uses \ in file paths.

In the file_helper.php library, line 289 to 295:

Code:
foreach ($returned_values as $key)
        {
            switch ($key)
            {
                case 'name':
                    $fileinfo['name'] = substr(strrchr($file, '/'), 1);
                    break;

Note the next to last line inside substr(). This causes the function to return false for the filename rather than correctly parsing out the filename.

The proof of bug code for windows systems:

Code:
$this->load->helper('file');
        
$files = get_dir_file_info('./');
        
var_dump($files);

You will quickly see 'name' array elements are boolean false due to this system incompatibility.

To fix:

Code:
case 'name':
                    $fileinfo['name'] = substr(strrchr($file, '/'), 1);

                    if (! $fileinfo['name'])
                    {
                        $fileinfo['name'] = substr(strrchr($file, '\\'), 1);
                    }
                    break;




Theme © iAndrew 2016 - Forum software by © MyBB