Welcome Guest, Not a member yet? Register   Sign In
Directory Separator bug with APPPATH and load_class
#1

[eluser]SBH[/eluser]
In index.php:
Code:
if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
    }
}
else
{
    // Swap directory separators to Unix style for consistency
    $system_folder = str_replace("\\", "/", $system_folder);
}
and in Common.php:

Code:
if (file_exists(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT))
    {
        require(BASEPATH.'libraries/'.$class.EXT);
        require(APPPATH.'libraries/'.config_item('subclass_prefix').$class.EXT);
        $is_subclass = TRUE;
    }
    else
    {
        if (file_exists(APPPATH.'libraries/'.$class.EXT))
        {
            require(APPPATH.'libraries/'.$class.EXT);
            $is_subclass = FALSE;
        }
        else
        {
            require(BASEPATH.'libraries/'.$class.EXT);
            $is_subclass = FALSE;
        }
    }

Both of these have the directory separator "/" hardcoded into strings rather than using DIRECTORY_SEPARATOR. Because of this, using xampp on windows, I cannot load auto config files because the path isn't correct and it switches between using / and \.

I'm pretty sure this is a bug but any insight would be great. I can't think of how to fix this other than changing all of these to DIRECTORY_SEPARATOR.

Thanks.
#2

[eluser]m4rw3r[/eluser]
I have never encountered any problems with using "/" on windows instead of backslash.

It is even possible to use / in the command prompt.
#3

[eluser]SBH[/eluser]
You're completely right! I found the problem and I think that it is a bug in the documentation.

This took me over a week of really learning the codeigniter code but the problem was that I was extending the native Email.php library but I wasn't passing the config object from my constructor to the original constructor.

I took what I needed to do directly out of the documentation because the docs discusses extending CI_Email but it doesn't mention passing the config to the constructor at all.
#4

[eluser]Unknown[/eluser]
Actually, still could be a bug.

I prefer to keep my system_folder below webroot so I did
Code:
line 26: $system_folder = realpath(dirname(__FILE__) . "/../system");

which on windows creates

Code:
$system_folder = 'D:\xampplite\htdocs\ominian.com\system'

So

Code:
if (strpos($system_folder, '/') === FALSE )

evaluates as a false postive.

Modified line ~63 to read
Code:
if (strpos($system_folder, '/') === FALSE && strpos($system_folder, '\\') === FALSE)

Furthermore the entire condition clause makes the assumption that realpath is going to a / delimited path instead of \, which isn't true on windows. Sad




Theme © iAndrew 2016 - Forum software by © MyBB