Reputation: 341
Am using XAMP 1.7.3 on Macbook pro osx 10.9 Firefox browser
Well basically i am trying to write a code asking the user to enter some information and then store the information in a .txt file using the:
$txtfile="registration.txt";
$handle=fopen($txtfile,'a');
But I keep getting the this error message :
Warning: fopen(registration.txt) [function.fopen]: failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 30
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 31
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 32
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 33
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 34
Warning: fwrite() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/UserInfoAhmed.php on line 35
full code is :
<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>
first i understood the first error message, failure to access / create the .txt file, and as i searched in this website, several ppl had the same problem, some the suggested a permission problem with the main file, and since every time i try to update the php file i get asked to enter my admin password, so i assumed the XAMP main file also protected
i changed the file option to read & write by all users, and all the folders within the main XAMP folder. but still i get asked for the password to save any changes in the php file am writing this code in, and thus i guess am still getting the same : fopen(registration.txt) [function.fopen]: failed to open stream: Permission denied in ...
so how could i fix this ? also am wondering if the rest of error messages related to the main problem ?
all in all, could someone tell me at least if there is a mistake in my code ?
Upvotes: 0
Views: 15920
Reputation: 738
First
Try to set registration.txt permissions via console:
sudo chmod 0777 /Applications/XAMPP/xamppfiles/htdocs/registration.txt
Second
If first didn't work then I think that you should change your htdocs folder location, because when it's in Applications folder it might not work properly because Applications folder might be somehow protected by system.
Edit your XAMPP apache httpd.conf and set DocumentRoot to /users/USERNAME/Documents/htdocs
Be sure to create htdocs folder under your Documents folder.
Then in console change folder permissions:
sudo chmod 0777 /users/USERNAME/Documents/htdocs
Then try to put some random file in the folder and try to open it in browser
http://localhost/randomfile.php
It should work. If you are getting internal server error (500) then comment out following line in httpd.conf:
LoadModule hfs_apple_module libexec/apache2/mod_hfs_apple.so
Upvotes: 1