尽管存在文件和777权限,php include_once失败 [英] php include_once failing despite existence of file and 777 permissions

查看:137
本文介绍了尽管存在文件和777权限,php include_once失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

php include_once失败了,因为无法打开流:没有这样的文件或目录消息,尽管存在它正在抱怨的文件,并且为了试图缓解问题而chmod到777 。

php include_once is failing for me with the "failed to open stream: No such file or directory" message, despite the existence of the file it is complaining about, and chmod'ing to 777 in order to try to mitigate the problem.

警告:include_once()[function.include]:无法打开'../i_utility/WCHelper.php'(include_path =': / usr / share / pear:/ var / www / html / we_ /')位于第6行的/var/www/i_/php/w_corner/modules/i_ers/i_ers.module。

从命令行我可以cd到包含源代码文件的目录(/ var / www / i_ / php / w_corner / modules / i_ers),我可以找到关于哪个文件的文件php抱怨没有这样:../ i_utility / WCHelper.php

From the command line I can cd to the directory containing the source code file (/var/www/i_/php/w_corner/modules/i_ers), and I can ls the file about which php complains "no such": ../i_utility/WCHelper.php

的确,我可以在sussing到apache用户后做到以上,甚至可以触摸该文件并查看其上次修改时间戳已更改:

Indeed, I can do the above after su'ing to the apache user, and can even touch the file and see its last modified timestamp changed:

-bash-3.2$ whoami
apache

-bash-3.2$ cd /var/www/i_/php/w_corner/modules/i_ers
-bash-3.2$ ls -l ../i_utility/WCHelper.php
-rwxrwxrwx 1 root root 32112 Sep 14 09:49 ../i_utility/WCHelper.php

-bash-3.2$ touch ../i_utility/WCHelper.php
-bash-3.2$ ls -l ../i_utility/WCHelper.php
-rwxrwxrwx 1 root root 32112 Sep 27 17:08 ../i_utility/WCHelper.php

鉴于上述所有情况,可能导致PHP的include_once在这些情况下失败的原因情况?

In light of all of the above, what could be causing PHP's include_once to fail under these circumstances?

推荐答案

PHP的包含路径有点违反直觉,特别是当你相对路径提供它时。您希望路径相对于当前文件(就像使用CSS一样),但PHP将它们解释为相对于当前工作目录,这通常是入口点PHP文件所在的目录(例如 /var/www/my_site/index.php )。

PHP's include paths are a bit counter-intuitive, especially when you feed it relative paths. You'd expect the path to be relative to the current file (just like with CSS for example), but PHP interprets them as relative to the current working directory, which is usually the directory where the entry point PHP file resides (e.g. /var/www/my_site/index.php).

最简单的解决方法是使用 dirname(__ FILE __),它始终映射到当前脚本文件的绝对位置。

The easiest fix is to make use of dirname(__FILE__), which always maps to the absolute location of the current script file.

这篇关于尽管存在文件和777权限,php include_once失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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