Function fopen(); Won't work.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pizzipie
Forum Commoner
Posts: 87
Joined: Wed Feb 10, 2010 10:59 pm
Location: Hayden. ID

Function fopen(); Won't work.

Post by pizzipie »

Warning: fopen(savechoice.txt) [function.fopen]: failed to open stream: Permission denied in

Code: Select all

 
<?php
    $partname=$_POST["partname"];
    $fp=fopen("savechoice.txt", "a+" );
    fwrite($fp,$partname);
    fclose($fp);    
?>
 
The file "savechoice.txt" doesn't exist, but I understand that "a+" will either append or create the file.

Can Anyone please tell me what the warning means and how to fix it?

Thanks in advance, Rick_P.
lshaw
Forum Commoner
Posts: 69
Joined: Mon Apr 20, 2009 3:40 pm
Location: United Kingdom

Re: Function fopen(); Won't work.

Post by lshaw »

It is probably permission problems

If you are on a local machine, right click the folder, click permissions and tick all the boxex, or if it is on a unix server set permisions to writable on FTP
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Function fopen(); Won't work.

Post by s.dot »

Yep, it is a permissions problem.

The folder you're attempting to create the file in must be writable by PHP. In an unsafe world, you could chmod the folder to 0777.. but this will give everyone read/write access to your folder. (this is what I do, even though I shouldn't).

I do believe to make it safe you should have php owned by apache instead of "nobody" and give it 755 permissions or 644.. I forget. I need to get back in the loop. :)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
pizzipie
Forum Commoner
Posts: 87
Joined: Wed Feb 10, 2010 10:59 pm
Location: Hayden. ID

Re: Function fopen(); Won't work. SOLVED !!!

Post by pizzipie »

:P :P :P

Thanks much guys. I changed the permissions to allow writing. SOLVED.

You would think that the people who dream up these Error and Warning messages would speak in plain english.

Again thanks!!

Rick_P
Post Reply