将 PHP 项目从 Linux 服务器迁移到 Windows 服务器时文件名中的斜线 [英] Slashes in file names when migrating PHP project to Windows server from Linux server

查看:47
本文介绍了将 PHP 项目从 Linux 服务器迁移到 Windows 服务器时文件名中的斜线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个在 Linux 平台上开发的 PHP 项目,现在我们希望它在 Windows 服务器上运行.我们现在面临文件路径的问题,该问题与反斜杠 &正斜杠.

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.

由于Windows服务器使用forward反斜杠,我们程序中的所有文件路径都变成了无效路径.现在我们必须编辑每个文件并更改斜杠.有什么简单的方法可以解决这个问题吗?

Since Windows server use forward 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?

推荐答案

你应该使用原生常量 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';

这篇关于将 PHP 项目从 Linux 服务器迁移到 Windows 服务器时文件名中的斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆