donglang6656 2018-09-15 15:43
浏览 6

PHP无法读取647下的文件

I'm just starting my studies on servers and file system in order to program a couple of utilities with PHP.

I have Apache set up as my local host at OS X. Just to make sure which user Apache is running as, I ran posix_getpwuid(posix_getegid())['name'] and it returned the expected _www. Then I went ahead and ran

$filename = '/Volumes/HDD/programming/PHP/sandbox/dir_permissions_tests/text.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}

At first I didn't want to create a separate group to add myself and Apache because I wanted to test how it would work if I added reading permission to "others". The output is also "The file does not exist". Then I added reading permission to all directories in the file path as pointed out at PHP can't read file with read permissions. Same problem. Then I added execution permissions as advised in the same link. No changes.

Am I wrong to presume that by having reading, writing and execution permissions set to all directories in the path and to the file itself for the "others" group PHP, by running under Apache _www should be able to find it regardless of the file and group it belongs to (that's why I'm trying under 647)? What am I missing? Maybe my understanding of "others" as "everything else" is not correct. I didn't intend to change ownership of all directories in the path just to make it work. Creating a separate group is an option, though, but I'd like to understand the issue with "others" first.

Many thanks.

  • 写回答

1条回答 默认 最新

  • dongtangxi1584 2018-09-16 07:05
    关注

    Problem solved. I changed the path from a root-relative to a document-relative one. Yet I would like some reference material to understand why root-relative ones don't work whereas in the function documentation at http://php.net/manual/en/function.file-exists.php a root-relative path is used in the examples.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?