Increasing a number on the first line of a file by 1 with php
<p>I have a script for counting the number of downloads of a file that I downloaded from the internet. Basically it has a log file that it adds a line of text every time the file is downloaded.</p>

<p>I want to modify it slightly so that the first line is a number, and every time a file is downloaded it increases that number by one (So it's easy to see exactly how many people have downloaded it.)</p>

<p>Here's the code I have right now (this isn't working):</p>

<pre><code>$conten = @file_get_contents(LOG_FILE);
//First line: $conten[0];

$content = fgets($conten);

$fo = @fopen(LOG_FILE, 'r+');
if ($fo) {
  $content++;
  @fputs($fo, ".$content.");
  @fclose($fo);
}


$f = @fopen(LOG_FILE, 'a+');
if ($f) {
  @fputs($f, date("m.d.Y g:ia")."  ".$_SERVER['REMOTE_ADDR']."  ".$fname."\n");
  @fclose($f);
}
</code></pre>

<p>The $f part works fine...it's the parts above that which aren't working like I want.</p>

<p>Thanks!</p>
