Error when styin to write to a file (failed to open stream)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psthree
Forum Newbie
Posts: 1
Joined: Sun Mar 01, 2009 6:26 pm

Error when styin to write to a file (failed to open stream)

Post by psthree »

I am trying to learn PHP and how to write to a file
i have Php up and running on a mac

when I try to write to a file
I get this error

/Library/WebServer/Documents/Php/read_write/config.txt

Warning: fopen(config.txt) [function.fopen]: failed to open stream: Permission denied in /Library/WebServer/Documents/Php/read_write/configure.php on line 77
ERROR: cannot open configuration file for writing

this is the code that generates the error

Code: Select all

//check file
    $configFile = 'config.txt';
    echo 'test<br>';
    echo file_exists($configFile). '<br/>';
    echo is_readable($configFile). '<br/>';
    echo is_writable($configFile). '<br/>';
    //echo stat($configFile). '<br/>';
    echo realpath($configFile). '<br/>';
    //open and lock configuration file for writing
    $fp = fopen($configFile, 'w+') or die ('ERROR: cannot open configuration file for writing');
    //flock($fp, LOCK_EX) or die ('ERROR: Cannot lock configuration file for writing');
 
I have check all the file permissions and they are set to read/write
if I change the file I am writing to to .txt instead of .ini
I get different results with the file_exists is_readalbe, is_writable tests
Is there perhaps a setting that must be set in the php.ini file?
thank you!
for any insite
Peter
psthree
Post Reply