【问题标题】:PHP and Apache file_exists not working from URLPHP 和 Apache file_exists 不能从 URL 工作
【发布时间】:2016-11-21 00:37:30
【问题描述】:

如果我从命令行运行,下面的代码有效(打印“找到文件”)查找

php a.php

但如果我尝试从浏览器http://localhost/a.php 访问它,它会打印“找不到文件”。

在不同的机器上,相同的 URL 可以正常工作,这真的很奇怪。我不知道为什么它不起作用。

我已经检查过 open_basedir 它已经被禁用并且 httpd.conf 中没有条目

 if(file_exists("/mnt/disk1/a.jpg"))
{ 
  echo "file found";
}     else
{ 
  echo "file not found";    }   ?>

【问题讨论】:

  • 你检查文件权限了吗?网络是否有足够的读取权限?
  • 是的,我已授予文件 777 权限
  • 你在尝试 clearstatcache() 吗?
  • 如果您想检查文件是否存在,您需要使用标题。通常,该功能仅适用于本地文件。

标签: php apache file-exists


【解决方案1】:

Web 服务器用户帐户必须具有读取文件的权限 - 这与您在控制台上使用的用户帐户不同。

sudo chmod +rx /mnt/disk1/a.jpg

Apache 还需要对所有文件夹的执行访问权限。

sudo chmod +x /mnt/disk1
sudo chmod +x /mnt

【讨论】:

  • 感谢 jeff 以某种方式创建文件夹 wittout 可执行权限
猜你喜欢
  • 2011-09-03
  • 1970-01-01
  • 2014-05-15
  • 2013-12-21
  • 2017-05-14
  • 2017-03-11
  • 1970-01-01
  • 1970-01-01
  • 2017-03-27
相关资源
最近更新 更多