帮助 Windows 路径 - PHP

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2334510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 06:05:10  来源:igfitidea点击:

Help with windows path - PHP

php

提问by jim

I have this path and it is correct however, the browser will not include the source file unless I put "file:///" in front of it. I'm still developing and this will ultimately be on a Linux machine but in the mean time, I'd like to see my work as well as be able to troubleshoot it. Is there a solution for this?

我有这个路径并且它是正确的,但是浏览器不会包含源文件,除非我在它前面加上“file:///”。我仍在开发中,这最终将在 Linux 机器上运行,但与此同时,我希望看到我的工作并能够对其进行故障排除。有解决方案吗?

This fails:

这失败了:

C:\Program Files (x86)\work\site\js\rowlock.js

This does not fail:

这不会失败:

file:///C:\Program Files (x86)\work\site\js\rowlock.js

回答by Silver Light

Try using variable $_SERVER['DOCUMENT_ROOT'] to make your script independent. For example:

尝试使用变量 $_SERVER['DOCUMENT_ROOT'] 使您的脚本独立。例如:

include($_SERVER['DOCUMENT_ROOT'].'/js/rowlock.js');

Works fine on any system

在任何系统上都能正常工作

回答by bcosca

just use front slashes everywhere if you'll be moving this to a linux box anyway. php for windows can understand it.

如果您无论如何都要把它移到 linux 机器上,请在任何地方使用前斜杠。php for windows 可以理解。

$file='c:/Program Files (x86)/work/site/js/rowlock.js';

回答by Andy

Put quotes around your path. You have spaces, so it is not read correctly.

在你的路径周围加上引号。您有空格,因此无法正确读取。

'C:\Program Files (x86)\work\site\js\rowlock.js'

回答by streetparade

Where is Your root folder?

你的根文件夹在哪里?

If its C:\Program Files (x86)\work\site\

如果它的 C:\Program Files (x86)\work\site\

Then simple access your file like this

然后像这样简单地访问您的文件

js/rowlock.js

js/rowlock.js

This assuming that js is in the Root folder

这假设 js 在 Root 文件夹中