I have a file named ‘views.txt’ which contains ‘0’.
When the user loads the page, I want the script to re-write the text document to one higher from the last.
Example;
<?php
$a = file_get_contents("views.txt")
$views = $a + 1;
file_put_contents("views.txt",$views);
echo $views;
?>
It won’t display anything.
I’m unable to use MySQL, so I’m using text files. 🙂
I would guess that the path to
views.txtis not relative to the working directory of the file. For safety reasons, you should probably specify the full path to the file; i.e.,/path/to/views.txt).You can also use getcwd to display the current working directory, so the location of “views.txt” will likely be
getcwd() . "/views.txt".