Adam Posted November 25, 2008 Share Posted November 25, 2008 Hey up guys. For a little project I'm involved with I've been trying to write a pretty simple config file handler class. Everything works great except my "commitChanges()" method. Although this is part of a class the problem isn't OO (so it's not in the OO forum) .. Here's the code: public function commitChanges() { // Ensure file is writable if (!is_writable($this->src)) $this->commitError('Config file un-writable!'); // Detect error opening file if ($handle = fopen($this->src, 'w') === false) $this->commitError('Unable to open config file!'); // Loop through each line of config file foreach ($this->config_arr as $key => $val) { // If a line has been altered... if (array_key_exists($key, $this->prop_name)) { // ...update that line $val = $this->prop_name[$key] . '=' . $this->prop_value[$key]; } print 'Writing: ' . $val . ' to file ... '; // Attempt to write to file and catch any errors if (fwrite($handle, $val) === false) print '[FAILED]'; else print '[sUCCESS]'; print '<br />'; } fclose($handle); return true; } I'm not getting any errors except my own "[FAILED]" message for each line. $this->src, $this->config_arr, $this->prop_name, $this->prop_value ...are all defined no problem. There is no problem with the foreach () either. My config file has all the right permissions (put it to chmod 0777 just to be sure). The problem purely lies with fwrite(). Has anybody come across this kind of problem before, or have any ideas what the problem could be? Cheers for any help! Adam Quote Link to comment https://forums.phpfreaks.com/topic/134176-fwrite-problem/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.