在 PHP 脚本中,检查文件是否可写时出现以下错误。
fopen(test.txt): failed to open stream: Permission denied
Run Code Online (Sandbox Code Playgroud)
请看打击详情:
Apache 服务以用户:apache 身份运行,检查如下:
ps aux | egrep '(apache|httpd)'
2.将要写入的文件和php脚本的所有权更改为apache。
chown apache:apache test.txt
chown apache:apache test.php
Run Code Online (Sandbox Code Playgroud)
3.文件权限改为:777
chmod 777 test.txt
chmod 777 test.php
Run Code Online (Sandbox Code Playgroud)
4.尝试过的设置:已经尝试过以下提供的解决方案:fopen Permission returned on a file with 777permissions
操作系统:红帽企业版
代码:
<?php
echo getmyuid().':'.getmygid();
echo "<br/>";
echo exec('whoami');
echo "<br/>";
$dst = 'test.txt';
echo $dst, file_exists($dst) ? ' exists' : ' does not exist<br/>', "<br/>\n";
echo $dst, is_readable($dst) ? ' is readable' : ' is NOT readable', …Run Code Online (Sandbox Code Playgroud) 当file_get_contents()用于在ftp://ipaddress/somefile.txt的FTP服务器上获取文本文件的文件内容时,我收到以下错误:
警告:file_get_contents()[ function.file-get-contents ]:connect()失败:第1行的filename.php中的权限被拒绝
但是当我在webbrowser中访问ftp://ipaddress/somefile.txt时,它绝对没有问题.
为什么我的浏览器可以打开文本文件,但file_get_contents()不能?
PS:我不知道它是否与它有关,但ini指令allow_url_fopen已经开启.