Slashes in file names when transferring a PHP project to a Windows server from a Linux server

We have a PHP project that is developed on the Linux platform, and now we want it to run on a Windows server. Now we have a problem with file paths, and the problem is with a backslash and a slash.

Since the Windows server uses forward backslash, all file paths in our program turn into an invalid path. Now we have to edit each file and change the slash. Is there an easy way to make this fixed?

+3
source share
1 answer

You should use your own constant DIRECTORY_SEPARATOR instead of entering (backward) the slash yourself, so your code will work on any platform.

$path = '.'.DIRECTORY_SEPARATOR.'mydir'.DIRECTORY_SEPARATOR.'myfile';

In addition, windows support backslashes and forward slashes, so you can just use slashes around the world.

For example, both of these work in a window:

$path = './mydir/myfile';
$path = '.\mydir\myfile';
+7
source

All Articles