除了 chdir() 和 chroot() 之外,还有什么可以更改 php Windows 中的目录? (Windows 中最简单的包含文件错误)

发布于 2024-09-10 22:17:23 字数 1345 浏览 2 评论 0原文

(抱歉,如果这个标题不好。我实际上正在尝试完成两件事 - 找出如何在 PHP 中更改当前目录,并修复在 WAMP 上运行的 Simpletest 中的错误。)

我正在运行 SimpleTest (simpletest.org )在我的 Windows 7 本地计算机上的 EasyPHP(WAMP 变体)上。

当我运行测试时,根据 getcwd(),目录从本地脚本目录更改回:C:\Program Files (x86)\EasyPHP\apache。

我创建了几个简短的脚本来检查 getcwd() 输出。它们按预期返回当前脚本路径:C:\Users\Burton\Desktop\Sites\dbmover。脚本:

serverpath/getcwd.php:

serverpath/tests/getcwd.php:

两者都返回当前路径:C:\Users\Burton\Desktop\Sites\dbmover

我通过 Simpletest 源进行了搜索以检查 chdir() 和 chroot() 的使用 - 唯一的方法。 Simpletest 不使用 chdir();

还有什么可以改变路径?

这个相对路径问题显然对于 Windows 中使用的 Simpletest 来说非常常见。 stackoverflow 上的这张海报有它, 与其他地方的这张海报一样。

一些 人们将问题视为正常,但我认为这是一个错误。

我自己一直在使用 dirname(__FILE__) 来解决这个问题,但我宁愿修复它以使其正常工作。

(Sorry if this is titled poorly. I'm actually trying to accomplish two things - find out how the current directory can get changed in PHP, and fix a bug in Simpletest running on WAMP.)

I'm running SimpleTest (simpletest.org) on my Windows 7 local machine on EasyPHP (a WAMP variation).

When I run tests, the directory changes from the local script dir back to: C:\Program Files (x86)\EasyPHP\apache according to getcwd().

I created a couple short scripts to examine getcwd() output. They return the current script path as expected: C:\Users\Burton\Desktop\Sites\dbmover. The scripts:

serverpath/getcwd.php: <? echo getcwd(); require_once('tests/getcwd.php) ?>

serverpath/tests/getcwd.php: <? echo getcwd(); ?>

Both return the current path: C:\Users\Burton\Desktop\Sites\dbmover

I did a search through Simpletest source to check for use of chdir() and chroot() - the only ways. Simpletest doesn't use chdir();

What else could be changing the path??

This relative path problem is apparently very common for Simpletest used in Windows.
This poster on stackoverflow has it,
as does this poster elsewhere.

Some people treat the problem as normal, but I think it's a bug.

I've been getting around it myself by using dirname(__FILE__) but I'd rather fix it to work correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜唯美灬不弃 2024-09-17 22:17:23

我从未使用过 simpletest,在不了解内部原理的情况下很难说。但是:调用的命令(exec / system / 等)可能会影响工作目录。值得注意的是,php 的 cgi 版本(不是 sapi cli)将其工作目录更改为脚本的工作目录,并且可能用于 php -l 语法检查和语法检查。其他应用程序。如果这是问题所在,请务必向其传递 -C 参数。

I have never used simpletest, and without knowing the internals it is difficult to say. However: commands called (exec / system / etc.) could influence the working dir. One of note is that the cgi version of php (not the sapi cli) changes it's working dir to that of a script, and could possibly be used for php -l syntax checks & other applications. If that's the problem, be sure to pass it the -C parameter.

只有影子陪我不离不弃 2024-09-17 22:17:23

事实证明,路径问题是由 Simpletest 的运行方式引起的。它有一个很酷的功能,称为“自动运行”,它基本上是第一个调用测试的文件顶部的包含文件。

它使用在脚本退出之前运行的 register_shutdown_function() 。但是,此函数运行的路径全部错误WAMP 的许多版本

我已提交针对此问题的错误修复< /a>.

顺便说一句,PHP 中可以更改目录的函数有:
系统()
执行()
chdir()
chroot()

Turns out that the path problem is caused by how Simpletest is run. It has a cool feature called "autorun", which is basically an include file at the top of the first file calling tests.

It uses register_shutdown_function() which runs just before the script exits. However, the path as this function runs is all wrong in many versions of WAMP.

I've submitted a bug fix for this problem.

BTW, functions that can change the directory in PHP are:
system()
exec()
chdir()
chroot()

喜你已久 2024-09-17 22:17:23

这听起来更像是一个 include_path 问题。 echo get_include_path(); 揭示了什么?

This sounds more like an include_path problem. What does echo get_include_path(); reveal?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文