且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将 PHP 项目从 Linux 服务器迁移到 Windows 服务器时文件名中的斜线

更新时间:2021-11-08 09:17:13

你应该使用原生常量 DIRECTORY_SEPARATOR 而不是自己输入(反)斜杠,这样你的代码就可以在任何平台上运行.

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';

另外,windows 支持反斜杠和正斜杠,所以你可以简单地在任何地方使用正斜杠.

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';