views:

100

answers:

3

Hi, I am confused with this code:

test.php:

fopen('test.txt','a+');

when I execute it, I get an error:

Warning: fopen(test.txt): failed to open stream:
     Permission denied in /var/www/html/yuelu3/mobile/text.php on line 2

test.txt:

-rwxrwxrwx. 1 jt jt     87 10月  7 20:58 test.txt

where is the problem?

Thanks a lot!I have found the problem,I use FC13,because of the protect of SELinux,some action is denied.So, I just need to get rid of the protect.

+1  A: 

Use fopn($_SERVER['DOCUMENT_ROOT'].'test.txt','a+');

THOmas
+1 And consider checking that file_exists also!
Sohnee
+3  A: 

try

fopen('/path/to/file/test.txt','a+');

as

fopen('test.txt','a+');

is most likely looking in another directory

Phill Pafford
A: 

Paths always cause issues when trying to open files. An easy way to avoid having any problems when you are attempting to open files is by checking what directory you are in, and where you are making the call to.

echo getcwd();

Create a simple PHP page and make a call print the current directory. Drop the PHP page into the same directory as the file, and it will tell you the correct path to the folder and then just add on the /filename.xxx.

Kyle