Search code examples
phplinuxiispathinclude

PHP deploying to Linux and Windows


Depending on whether I'm deploying my website to Linux or Windows, I set my include paths like this: -

if(PHP_OS==="WINNT")
    include("..\\library\\chopper.inc");
else 
    include("/home/site/wwwroot/library/chopper.inc");

I'm sure this isnt the best way to do this!

Whats the correct way of setting the paths depending upon the environment?


Solution

  • you could try to use PHP's predefined constant DIRECTORY_SEPARATOR which gives you an OS-specific directory delimiter. DIRECTORY_SEPARATOR separates the directories within the path: In Windows '' In other systems'/'

    https://www.php.net/manual/en/dir.constants.php

    https://www.php.net/manual/en/function.set-include-path.php