0

我有以下情况:

public_html - 755

=> 头像 - 777

=> 民意调查 - 755

现在,当我使用以下代码时,我会收到一个错误(警告:file_put_contents(../test.php) [function.file-put-contents]: failed to open stream: Permission denied in XXX):

<?php
file_put_contents('../test.php','<?php');
?>

但是当我使用下面的代码时,它会工作得很好:

<?php
file_put_contents('test.php','<?php');
?>

(均从 'avatar' 执行,使用 0777)

我该如何解决这个问题?

4

2 回答 2

1

由于您的脚本是从avatar具有0777权限(世界读/写/执行)的 执行的,因此您能够在其中创建文件是正常的(即:)file_put_contents("test.php")

如果您无法在public_html(ie: file_put_contents("../test.php")) 中创建文件,那是因为执行您的脚本的用户(很可能是 Apache 用户)不是public_html(很可能是 FTP 用户)的所有者。因为0755意味着只有所有者才能写入目录,所以其他人只能读取或执行该目录。

如果您具有 shell 访问权限,则可以使用chown来更改文件的所有者:

bash-4.1.5$ chown newuser public_html

或者您可以chmod对非所有者拥有更高的权限,但您应该小心。

于 2010-12-30T03:12:05.980 回答
0

我想即使您拥有 0777 权限,也无法写入更高的文件夹。

不能在这个目录上使用 chmod,你必须使用 FTP 或其他东西。

于 2010-12-30T03:06:22.943 回答