file_exists() 找不到文件
if(file_exists("./squadra/photos/photog.jpg")) {
echo "### YES ###";
} else {
echo "### NO ###";
}
如果我在 /zones/team.php 上运行这个函数,它就可以工作(它打印 YES)。如果我在 /auth/ajax.php 上运行此函数,它会打印“否”。为什么?
编辑
所以我做了一些实验。
1 - 如果我尝试:
// file on /zones/team.php
if(file_exists($_SERVER['DOCUMENT_ROOT']."/squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
// file on /auth/ajax.php
if(file_exists($_SERVER['DOCUMENT_ROOT']."/squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
它都说“不”;
2 - 如果我尝试:
// file on /zones/team.php
if(file_exists("./squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
// file on /auth/ajax.php
if(file_exists("../squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
两者都说“是”;但是在 team.php 上我使用 ./ 并在 ajax.php ../ 上使用...为什么这有效???
if(file_exists("./squadra/photos/photog.jpg")) {
echo "### YES ###";
} else {
echo "### NO ###";
}
if i run this function on /zones/team.php it works (it print YES). If i run this function on /auth/ajax.php it print NO. Why?
EDIT
So i make some experiment.
1 - If i try :
// file on /zones/team.php
if(file_exists($_SERVER['DOCUMENT_ROOT']."/squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
// file on /auth/ajax.php
if(file_exists($_SERVER['DOCUMENT_ROOT']."/squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
it says NO on both;
2 - If i try :
// file on /zones/team.php
if(file_exists("./squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
// file on /auth/ajax.php
if(file_exists("../squadra/photos/provag.jpg")) {
echo "YES";
} else {
echo "NO";
}
it says YES on both; But on team.php im using ./ and on ajax.php ../ ...why this works???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您的最后一个之所以有效,很可能是因为:
index.php
调用zones/team.php
。在这种情况下,./
部分正确标识了您的当前目录。auth/ajax.php
一样直接调用它,而不是像index.php?type=jx&do=auth/ajax
这样的东西与No.1相同。因此,情况并非如此,您需要首先使用../
退出auth
,然后继续使用squadra/...
>。尽可能多地使用绝对路径。相对路径对于 PHP 来说计算它们是一件痛苦的事(在性能方面)。
Your last one works most probably because:
zones/team.php
from anindex.php
which resides in root. In this case./
part correctly identifies your current directory.auth/ajax.php
, instead of something likeindex.php?type=jx&do=auth/ajax
which would be the same as No.1. Hence this is not the case, you need to get out ofauth
first with../
, and then go on withsquadra/...
.Use absolute paths as often as you can. Relative paths are a pain for PHP to calculate them (in performance-wise).
确保您正在考虑您输入的文件夹。文件地址以 / 开头,它是服务器端根目录。如果您想要本地目录,请删除前面的 / 或键入整个路径。
其次确保没有错别字。
祝你好运!
Make sure you are considering the folder that you have typed. You start the file address with / which is server side root. If you want local directory, either remove the preceeding / or type out the entire path.
Secondly make sure you have no typos.
Good luck!
当你有一个正斜杠时,file_exist 将转到 HDD 的根目录。
在其前面使用 $_SERVER['DOCUMENT_ROOT'] 或删除斜线并使用 ../ 等。
As you got a forward slash, file_exist will go to the root of the HDD.
Use $_SERVER['DOCUMENT_ROOT'] in front of it or remove the slash and use ../, etc, etc.
如果squadra是PHP脚本运行目录下的目录,请尝试
If squadra is a directory under the directory where the PHP script is running, try
检查 php safe_mode 状态,
并检查文件路径的大小写敏感性。
php file_exists
Check the php safe_mode status,
and check the case sensitivity of the file path.
php file_exists
如果您使用 file_exists 的相对路径,它将返回 false,除非该路径相对于 php 目录。
If you use a relative path with file_exists it returns false unless the path is relative to the php directory.
再次检查路径 - 我认为前导斜杠是一个错误 - 因为它可能指向根(服务器或更可能的用户空间) - 而您的执行脚本可能位于子路径中...
tl;博士;尝试删除第一个“/”
Check for the path again - I think that the leading slash is a mistake - as it may point to the root (either server or more likely user space) - while your executing script may be located in a sub-path...
tl;dr; Try removing the first "/"