Jump to content

fwrite()


SharkBait

Recommended Posts

I am having issues.

I use the following:
[code]
<?php

$filename = "testfile.txt";

if(!$handle = fopen($filename, 'a+')) {
  echo "Cannot open file";
}
?>
[/code]

Now I get an Permission Denied warning and the Cannot open file error when I try to open/write a file.

It seems (if the file exists) the file that is to be written to needs to be 777 for it to work.  Isn't the a+ argument supposed to create the file and open it if its not there??  The script itself has 777 permissions.

What I want to do is if the file doesn't exists, create it and change the permission so that I can write to it properly.
What am I doing wrong?
Link to comment
https://forums.phpfreaks.com/topic/24569-fwrite/
Share on other sites

[quote author=SharkBait link=topic=112147.msg455140#msg455140 date=1161372941]
Or is it best to put it into a subdirectory of its own and 777 that subdir?
[/quote]

bingo... however, if possible, you should set up your apache user to have group permissions so you can set your folder to 755 or 775 instead of 777.
Link to comment
https://forums.phpfreaks.com/topic/24569-fwrite/#findComment-112027
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.