SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: PHP Paths on Windows Servers
-
May 6, 2009, 16:17 #1
- 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)) {
}
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.
-
May 6, 2009, 16:33 #2
- 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.
-
May 6, 2009, 17:00 #3
- Join Date
- Jul 2008
- Posts
- 32
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ah, that's what I'm looking for. Thanks.
-
May 6, 2009, 17:28 #4
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...
-
May 6, 2009, 19:40 #5
- 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