Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
302 views
in Plugins by

I am writing a hit counter plugin for Q2A. I used qa-plugin.php to register a widget module. Here is part of the code:

 

<?php
$file = fopen('hits.txt','r+') or exit('Unable to open file.');
$current = fgets($file) + 1;
rewind($file);
fwrite($file, $current) or exit('Unable to write to file.');
fclose($file);
echo $current;
?>
 
I am getting the error "Unable to open file", even though I set the permissons to 777. Any ideas?
Q2A version: 1.4.3

1 Answer

0 votes
by

Why not just:

<?php
$file 
'people.txt';
// Open the file to get existing content
$current file_get_contents($file);
// Append a new person to the file
$current .= "John Smith\n";
// Write the contents back to the file
file_put_contents($file$current);
?>

?

by
Thanks for the reply Noah. The problem is I can't do anything with a file because file_exists('hits.txt') always returns FALSE even though the file is there.
by
check file and directory permissions and ownership
...