开发者

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

开发者 https://www.devze.com 2023-03-08 22:56 出处:网络
We have a PHP project which is developed on a Linux platform and now we want that to be run on a Windows server. We now face a problem with file paths and the problem is related to back slash & fo

We have a PHP project which is developed on a Linux platform and now we want that to be run on a Windows server. We now face a problem with file paths and the problem is related to back slash & forward slash.

Since Windows server use f开发者_StackOverflow社区orward back slash, all the file paths in our program turns to invalid path. Now we have to edit each file and change the slash. Is there any easy way to get this fixed?


You should be using the native constant DIRECTORY_SEPARATOR instead of entering the (back)slash yourself, this way your code will work on any platform.

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

Also, windows support both back and forward slashes, so you can simply uses forward slashes everywhere.

eg both of these work on window:

$path = './mydir/myfile';
$path = '.\mydir\myfile';
0

精彩评论

暂无评论...
验证码 换一张
取 消