Php file\u put\u内容和file\u get\u内容在其他目录下不工作

Php file\u put\u内容和file\u get\u内容在其他目录下不工作,php,file-io,Php,File Io,尽管file_put_内容和file_get_内容适用于/var/www/html/,但它们不适用于具有相同所有者(apache)和chmod(644)的任何其他目录。原因可能是什么?谢谢你的帮助 编辑: 工作代码: $contents = file_get_contents("/var/www/html/osman"); $contents = str_replace("mehmet", '', $contents); file_put_contents("/var/www/html/osma

尽管file_put_内容和file_get_内容适用于
/var/www/html/
,但它们不适用于具有相同所有者(apache)和chmod(644)的任何其他目录。原因可能是什么?谢谢你的帮助

编辑:

工作代码:

$contents = file_get_contents("/var/www/html/osman");
$contents = str_replace("mehmet", '', $contents);
file_put_contents("/var/www/html/osman", $contents);
$contents = file_get_contents("/opt/blaris/etc/webfilter/lists/osman");
$contents = str_replace("mehmet", '', $contents);
file_put_contents("/opt/blaris/etc/webfilter/lists/osman", $contents);
非工作代码:

$contents = file_get_contents("/var/www/html/osman");
$contents = str_replace("mehmet", '', $contents);
file_put_contents("/var/www/html/osman", $contents);
$contents = file_get_contents("/opt/blaris/etc/webfilter/lists/osman");
$contents = str_replace("mehmet", '', $contents);
file_put_contents("/opt/blaris/etc/webfilter/lists/osman", $contents);
正如我之前所悲伤的,两个文件拥有相同的所有者和chmod…

易卜拉欣

正如您提到的,两个函数(get和put)都返回false。我很确定这是由于设置文件/目录权限不当造成的(前段时间也有同样的问题…)

我通过检查路径(在您的案例中是“/opt/blaris/etc/webfilter/lists/”)来解决这个问题,如果所有权限都设置为应该设置的权限。这还包括对列表目录本身和上面所有目录的读/写权限

因此,请确保路径中的所有目录(至少)可由apache用户执行(例如
apache用户是否可以执行/opt?
/opt/blaris是否可执行…
/opt/blaris/etc是否可执行。。。 )

还要确保PHP脚本确实在apache用户下运行(
应该提供信息)

如果您想在shell级别对其进行调试,可以尝试以下命令,并查看输出内容(如果您有权在服务器上执行该命令…):

sudo-u apachetouch/opt/blaris/etc/webfilter/list/osman
希望有帮助;)

当您尝试使用另一个目录时,是否收到任何特定的错误消息?是否显示一些代码?@Demento否他们只返回错误文件还必须具有写入权限,而不仅仅是directories@knittl所有目录和文件都有写权限,其所有者是apache。。。