Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2007
    Location
    Canada
    Posts
    49
    Thanks
    1
    Thanked 1 Time in 1 Post

    Dealing with Linux and Windows paths

    As we all know, Linux and Windows use different file system path nomenclature. In the app I am trying to write, I need to do file level work (create dir's, upload and move files, etc...). How do you typically deal with the differences between the two file systems when you create the file system paths?

    For example:
    Linux: mkdir('/home/e-smith/app/new_dirname')
    Windows: mkdir('d:\wamp\www\app\new_dirname')

    How do you make you app easy to switch between Linux/Unix and Windows?

    The only method I can see at this point is to define two constants and manually edit them upon install. Create a ROOT_PATH and a PATH_SEPARATOR and use these when constructing the necessary file paths.
    Something like:
    PHP Code:
     $path=$ROOT_PATH $PATH_SEPARATOR 'new_dirname'
    Is there a better way?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    I would use the $_SERVER predefined constants.
    $ROOT_PATH = $_SERVER['DOCUMENT_ROOT'];
    or maybe PATH_TRANSLATED
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    You could use $_SERVER['DOCUMENT_ROOT'] which is the directory that the current file is in.

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,019
    Thanks
    2
    Thanked 313 Times in 305 Posts
    Windows accepts both the \ and / -
    On Windows, both slash (/) and backslash (\) are used as directory separator character. In other environments, it is the forward slash (/).
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •