PHP function.fopen无法打开流:权限被拒绝
我在ubuntu 12上运行apache,无法使用fopen函数打开特定文件。我可以在同一个php文件中打开其他文件。 以下是错误: 警告:fopen(file.txt)[function.fopen]:无法打开流:第10行的/../../../../../../..php中的权限被拒绝PHP function.fopen无法打开流:权限被拒绝,php,fopen,Php,Fopen,我在ubuntu 12上运行apache,无法使用fopen函数打开特定文件。我可以在同一个php文件中打开其他文件。 以下是错误: 警告:fopen(file.txt)[function.fopen]:无法打开流:第10行的/../../../../../../..php中的权限被拒绝 警告:fwrite()希望参数1是第11行的/../../../../../../..php中给定的资源布尔值 警告:fclose()要求参数1是资源,布尔值在第12行的/../../../../../../p
警告:fwrite()希望参数1是第11行的/../../../../../../..php中给定的资源布尔值
警告:fclose()要求参数1是资源,布尔值在第12行的/../../../../../../php中给出
警告:无法修改标题信息-标题已由第20行的/../../../../../../../..php中的/../../../..php:10开始输出)发送 我的代码:
<?php
session_start();
$username = $_SESSION['username'];
$amount = $_SESSION['amount'];
$message = $_SESSION['message'];
$send = "$username donated $amount";
$Vdata = file_get_contents('donation.txt');
$cumoney = file_get_contents('money.txt');
$newmoney = $amount + $cumoney;
$handle4 = fopen("money.txt", "w");
fwrite($handle4, $newmoney);
fclose($handle4);
if($Vdata == $send){
$handle = fopen("donation.txt", "w");
fwrite($handle, $username ." donated ". $amount);
fclose($handle);
$handle2 = fopen("donationmsg.txt", "w");
fwrite($handle2, $message);
fclose($handle2);
header ("Location: ...");
}else{
$handle = fopen("donation.txt", "w");
fwrite($handle, $username ." donated ". $amount);
fclose($handle);
$handle2 = fopen("donationmsg.txt", "w");
fwrite($handle2, $message);
fclose($handle2);
header ("Location: ...");
}
?>
这看起来像是权限问题。您应该确保您和您的脚本具有访问该文件及其所在目录的权限 显然,PHP没有对该文件的写入权限。
这是在Ubuntu PHP上以与Apache相同的用户身份运行的,因此请确保该文件可由www-data
组写入
user@host:/path/to/your/file# chgrp www-data yourfile.txt
user@host:/path/to/your/file# chmod g+w yourfile.txt
你能把你的密码贴出来吗?问题是我什么时候开门。。。你需要一些缩进,我的朋友。我不能添加+w,不起作用。我尝试了chgrp www data dir,但没有成功对不起,我的命令搞错了。我用命令testet更新了答案,以便在Ubuntu上安装。