Board index   FAQ   Search  
Register  Login
Board index System Administration Server installation and configuration

fopen on local server: permission denied

Discuss server installationa nd configuration issues here

Moderators: macek, egami, gesf

fopen on local server: permission denied

Postby pedrolc » Thu Dec 01, 2011 6:02 pm

Hello, everyone.

This is a really beginner question. I'm trying to learn php. To do so, I started reading w3 schools php lessons and some other basic stuff. Right now, I'm using Mac Os Lion.

According to this tutorial - http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/ - php is working here. Unfortunately, I'm having some troubles trying to execute the following code:

Code: Select all
<html>
<body>

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$fp = fopen("formdata.txt", "w");
$savestring = $name . "," . $email . "n";
fwrite($fp, $savestring);
fclose($fp);
echo "<h1>You data has been saved in a text file!</h1>";
?>

</body>
</html>


When I say "execute the following code", I mean "open the .php file on Firefox, making sure the file is located at localhost".

This is what appeared on my screen:

Warning: fopen(formdata.txt) [function.fopen]: failed to open stream: Permission denied in /Library/WebServer/Documents/save.php on line 7

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Library/WebServer/Documents/save.php on line 9

Warning: fclose() expects parameter 1 to be resource, boolean given in /Library/WebServer/Documents/save.php on line 10


I've googled it, but didn't find any solutions. I appreciate if you could help me here.
pedrolc
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Dec 01, 2011 5:46 pm

Re: fopen on local server: permission denied

Postby egami » Fri Dec 02, 2011 5:52 am

it's a file permissions error, most likely.

chmod 777 filename (do this only temporarily, as it's a big security risk)

and see if you still get the same problems.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: fopen on local server: permission denied

Postby pedrolc » Wed Dec 07, 2011 3:07 pm

Thanks, egami! It worked fine and I have already changed the folder permissions to the initial configuration.

Now that I known the problem and the inappropriate solution, could tell me what I actually should do? =]
pedrolc
New php-forum User
New php-forum User
 
Posts: 2
Joined: Thu Dec 01, 2011 5:46 pm

Re: fopen on local server: permission denied

Postby egami » Thu Dec 08, 2011 5:11 am

change the mode to 775, and set the group to the apache/webserver user.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT


Return to Server installation and configuration

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron