2011-04-26 118 views
0

尽管file_put_contents和file_get_contents适用于/var/www/html/,但它们不适用于具有相同所有者(apache)和chmod(644)的任何其他目录。可能是什么原因?感谢您的帮助...file_put_contents和file_get_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。 ..

+0

你得到任何特定的错误消息,当您尝试使用另一个目录? – Demento 2011-04-26 06:40:08

+0

如何显示一些代码? – 2011-04-26 06:42:27

+0

@Demento不,他们只返回false – ibrahim 2011-04-26 06:48:14

回答

1

易卜拉欣

正如你所说的那样,函数(get和put)返回false。我很确定这是由不正确的设置文件/目录权限(前一段时间有同样的问题)造成的。

我解决它通过检查路径(在你的情况“的/ opt/blaris的/ etc/web过滤器/列表/”),如果所有的权限设置,因为他们应该。这还包括列表目录本身和上述所有目录的读/写权限。

所以由Apache用户请确认您的路径中的所有目录(至少)可执行文件(如
是/ opt可执行apache用户?
是/ opt/blaris可执行...
是/ opt/blaris /等可执行... )

还要确保PHP脚本apache用户下运行真的(<?php echo shell_exec('whoami'); ?>应该给你的信息)

如果你想调试它的外壳级别,你可以尝试以下命令并查看wh在输出端说(如果你有权利在服务器上执行命令):

sudo -u apache touch /opt/blaris/etc/webfilter/lists/osman

希望帮助;)