Welcome Guest, Not a member yet? Register   Sign In
Bug in ci/index.php concerning server path?
#1

[eluser]Unknown[/eluser]
I've had some issues with backslashes appearing in my $system_folder (BASEPATH).
I'm developing on Windows XP using WAMPSERVER 2.0, and Codeigniter 1.7.2.

I've set system folder as indicated by the manual:
$system_folder = "system";

Then..

Code:
<?php echo BASEPATH; ?>

Gives me the following result:

Code:
C:\wamp\www\ci/system

To solve this I added the "swap directory seperator to unix style" into line 68 in ci/index.php:

Code:
if (strpos($system_folder, '/') === FALSE)
{
    if (function_exists('realpath') AND @realpath(dirname(__FILE__)) !== FALSE)
    {
        $system_folder = realpath(dirname(__FILE__)).'/'.$system_folder;
            // Swap directory separators to Unix style for consistency
            $system_folder = str_replace("\\", "/", $system_folder);
    }
}

BASEPATH now gives me the expected result:

Code:
C:/wamp/www/ci/system/

Is this a bug?
#2

[eluser]WanWizard[/eluser]
That's why PHP as invented the constant DIRECTORY_SEPARATOR, which you should use instead of hardcoding a (back)slash to be used in a path...
#3

[eluser]Unknown[/eluser]
Thanks for the heads up, but shouldn't Codeigniter include this by default in ci/index.php?

*EDIT* I also read the comment on php.net regarding that DIRECTORY_SEPARATOR is uncessary since Windows will accept forward slash, but I guess its good for exploding a path though.
#4

[eluser]WanWizard[/eluser]
For PHP, it's not a problem to use Unix style directory separators in a Windows environment. Problem starts with user input (who are used to C:\), and certain PHP functions, like realpath, that return backslashes on a Windows platform.

I would say that CI should work uniformly, so on a Windows platform, make sure everything is using backslashes, and on other platforms, use forward slashes. In which case all hardcoded slashes need to be replaced by DIRECTORY_SEPARATOR. And yes, in core code CI should take care of this.




Theme © iAndrew 2016 - Forum software by © MyBB