我在 Macbook pro osx 10.9 Firefox 浏览器上使用 XAMP 1.7.3
好吧,基本上我正在尝试编写一个代码,要求用户输入一些信息,然后使用以下命令将信息存储在 .txt 文件中:
$txtfile="registration.txt";
$handle=fopen($txtfile,'a');
但我不断收到此错误消息:
警告:fopen(registration.txt)[function.fopen]:无法打开流:第 30 行 /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php 中的权限被拒绝
警告:fwrite() 期望参数 1 是资源,布尔值在第 31 行的 /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php 中给出
警告:fwrite() 期望参数 1 是资源,布尔值在第 32 行的 /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php 中给出
警告:fwrite() 期望参数 1 是资源,布尔值在第 33 行的 /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php 中给出
警告:fwrite() 期望参数 1 是资源,布尔值在第 34 行的 /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php 中给出
警告:fwrite() 期望参数 1 是资源,布尔值在第 35 行的 /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php 中给出
完整代码是:
<html>
<head>
<title>User Informations</title>
</head>
<body>
<form method="post" action="">
Name : <input type="text" name="name"/> <br>
Age : <input type="text" name="age"/> <br>
City : <input type="text" name="city"/> <br>
Password: <input type="password" name="pswrd1"/> <br>
Password: <input type="password" name="pswrd2"/> <br>
<input type="submit" name="submit" value"send"/>
<form/>
<?php
if(isset($_POST['submit']))
{
$name=$_POST["name"];
$age=$_POST["age"];
$city=$_POST["city"];
$pswrd1=$_POST["pswrd1"];
$pswrd2=$_POST["pswrd2"];
if($pswrd1 == $pswrd2){
if($city==dubai){
if($age>18){
$txtfile="registration.txt";
$handle=fopen($txtfile,'a');
fwrite($handle, $name);
fwrite($handle, $age);
fwrite($handle, $city);
fwrite($handle, $pswrd1);
fwrite($handle,$pswrd2);
}
else echo "age must be > 18";
}
else echo "city must be dubai";
}
else echo "password must identical";
echo "<br>";
}
?>
</body>
首先我理解了第一条错误消息,无法访问/创建.txt文件,当我在这个网站上搜索时,有几个人有同样的问题,有些人建议主文件的权限问题,因为每次我尝试更新 php 文件我被要求输入我的管理员密码,所以我假设 XAMP 主文件也受到保护
我将文件选项更改为由所有用户以及 XAMP 主文件夹中的所有文件夹读取和写入。但是我仍然被要求输入密码以保存在写入此代码的 php 文件中的任何更改,因此我想我仍然得到相同的结果:fopen(registration.txt) [function.fopen]: failed to open stream: Permission拒绝...
那么我该如何解决呢?还想知道其余的错误消息是否与主要问题有关?
总而言之,如果我的代码有错误,至少有人可以告诉我吗?