note 43878 added to function.file-get-contents
| From: | scott-SPAM at abadox dot biz | Date: | Wed, 07 Jul 2004 03:22:54 +0000 |
| Subject: | note 43878 added to function.file-get-contents | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-72807@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.file-get-contents.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+43878
Delete -- http://master.php.net/manage/user-notes.php?action=delete+43878&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+43878&report=yes
Search -- http://master.php.net/manage/user-notes.php