【发布时间】:2012-03-01 23:40:41
【问题描述】:
这个问题已被问过很多次,但我找到的答案都没有帮助我。
我正在尝试让 php file_exists() 工作。唯一可行的情况是当 php 文件与要使用 file_exist() 的文件位于同一目录中并且仅使用文件名(即不包括路径)时。但这不是随之而来的行为,请参见下文。
索姆信息:
- safe_mode=off
- 目录 28 没有符号链接
- 文件名中没有空格
- /var/www/html/smic/upload/28/ 中的所有目录都具有 apache:apache 777 作为权限。
- 使用 php 5.3
PHP:
echo getcwd()
clearstatcache();
$file = 'file:///var/www/html/smic/upload/28/ul.txt';
//Also tried like this
//$file = '/var/www/html/smic/upload/28/ul.txt';
if(file_exists($file)){
echo $file." exists";
}
getcwd() 打印 /var/www/html/smic/modules/core/ticket
php-script的权限和要检查的文件是apache:apache 777。
目录结构的一些细节:
[root@localhost 28]# pwd
/var/www/html/smic/upload/28
[root@localhost 28]# ls -l ul.txt
-rw-r--r--. 1 apache apache 2 Feb 9 10:50 ul.txt
[root@localhost 28]# chmod 777 ul.txt
[root@localhost 28]# ls -l ul.txt
-rwxrwxrwx. 1 apache apache 2 Feb 9 10:50 ul.txt
更改文件的权限后行为没有改变。目录 /28 有 drwxr-xr-x。对于 apache 用户和 apache 组
为了测试,我还将实际的 php-script 移动到 /28,给它 apache:apache 777 rigths。将 $file 更改为“ul.txt”(即 $file = 'ul.txt';)。这行得通,找到了 ul.txt 文件。
getcwd() 然后打印 /var/www/html/smic/upload/28
作为另一项测试,我试图在“ticket”目录中查找不包括路径的另一个文件,但该文件无法识别。
我在敲我的头......
感谢任何建议。
【问题讨论】:
-
你用的是哪个版本的php?你试过没有
file://方案吗? -
PHP 5.3,已添加到我的帖子中。我几乎只尝试过没有 file://
标签: php linux file-upload file-exists