note 43878 deleted from function.file-get-contents by tomsommer

From: Date: Wed, 07 Jul 2004 07:13:35 +0000
Subject: note 43878 deleted from function.file-get-contents by tomsommer
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-72813@lists.php.net to get a copy of this message
Note Submitter: scott-SPAM@abadox.biz ---- I was writting a simple counter function <?php function pageCounter() { $file = 'inc/counter.dat'; if (!file_exists($file)) { touch($file); } $cnt = file_get_contents($file); if ($cnt == false) { die(); } $fx = fopen($file, 'w'); $cnt++; fwrite($fx, $cnt); fclose($fx); return $cnt; } ?> for a new website I was working on and for some reason, it kept dieing on me. After I investigated I found that $cnt equal'd false. So I dug around some more and discovered that the file_get_contents function seems to fail (or return false) on an empty file, or in my case when the function created a blank file for the function to use. Hope this saves you some time ^_^ -Scott

« previous php.notes (#72813) next »