Jump to content

Archived

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

SharkBait

fwrite()

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?

Share this post


Link to post
Share on other sites
does the [b]folder[/b] into which you're trying to write your file have writable permissions? that's key. the file itself needs them, yes, but if the folder in which you are trying to create a file doesn't, you're hosed.

Share this post


Link to post
Share on other sites
So i would have to turn the entire folder that the file sits in to writable?  geesh that seems a bit of a security issue...

Or is it best to put it into a subdirectory of its own and 777 that subdir?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
I'll look into that as well. Thanks Obsidian, thanks others too :)

Share this post


Link to post
Share on other sites

×

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.