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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.