![]() |
I need some help with files
I seem to have hit a snag with PHP, if anyone can lend a hand...
This is the code I used: :
<HTML>What I want to do is open a file called "test.txt", read the value stored inside (an integer), increment the integer and store it back into the file. It's a kind of counter. The above code gives the following error: Fatal error: Call to undefined function: fprintf() in C:\Program Files\BadBlue\PE\files\test.php on line 21 But the functions printf, fwrite and fread are working and PHP is functional, part for this fprintf thing :eek: |
change:
[php] if (fprintf ($handle, "%d", $myvalue) === FALSE) [/php] to: [php] if (!fwrite($handle, $myvalue)) [/php] |
Personally, i think an easier alternative would be...
[php] function incFile($file) { $val = intval(readfile($file)); fopen($file, "w") or die("Could not open \"{$file}\"!"); fwrite($file, $val+1); fclose($file); } incFile("test.txt"); [/php] |
Thank you, your suggestions seem to work
|
| All times are GMT -5. The time now is 6:26 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC