SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Paths on Windows Servers

    Hi,

    I'm making a PHP application. I want it to work on both Linux and Windows servers. I'm familiar with Linux servers, and I have some code like this:

    PHP Code:
    if (!file_exists($userFolder "/" $folderName)) {

    Notice how I used a forward slash ("/"). As I'm aware, Windows filepaths use the backslash ("\") instead.

    I tested filepaths with the forward slash on my Windows XP and I can still access folders with forward slashes (on my PC, NOT a server). So will it work on a server?

    However, I'm wondering if my code will work in the following settings:

    Windows/IIS
    Windows/Apache

    Will it work on legacy Windows server platforms?

    Or should I re-write the code to account for Windows server platforms?

    Thanks.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    windows will work with either, although php does provide the DIRECTORY_SEPARATOR constant if you want. This is nice if you want to do some of your own file path manipulation using explode and such.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2008
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah, that's what I'm looking for. Thanks.

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    When I ever work with paths, I always run the path though a normalizer. For example:
    PHP Code:
    $path preg_replace'~[\\\\/]+~''/'realpath$path ) . '/' );
    if ( !
    $path || !file_exists$path ) )
        
    // error... 
    To determine weather your PHP applications works on IIS/Apache, Windows/Linux you need to actually test.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  5. #5
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The Windows API takes in slashes of both sort (though not all Windows programs do), and it does not matter what web server you use.


Bookmarks

Posting Permissions

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