Page 1 of 1
Function fopen(); Won't work.
Posted: Tue Feb 23, 2010 1:54 pm
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.
Re: Function fopen(); Won't work.
Posted: Tue Feb 23, 2010 2:07 pm
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
Re: Function fopen(); Won't work.
Posted: Tue Feb 23, 2010 2:12 pm
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.

Re: Function fopen(); Won't work. SOLVED !!!
Posted: Wed Feb 24, 2010 11:06 am
by pizzipie
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