title: Bug fread in a txt file, read only one time
body: <p>I'm creating a code to display the name of a server with enterprise rules, So for don't use <code>Mysql</code> i try a new things (for me) use php to read and rewrite files, that work perfectly for one part of my code and work perfectly but for the second he only read one time, and when i do a f5 the code don't increment.
  He rewrite correctly because my file was at 000 and become 001</p>
  
  <p>I try to use <code>file()</code> but he is disable since <code>7.0</code>, try to use SplFileObject but it don't want to display anything and i don't like it because i understand nothing when i use it so i come back to <code>fopen()</code>,<code>fread()</code> and <code>fwrite()</code> and that don't work. I'm in<code>PHP 7.3.1</code></p>
  
  <p>The code that works :</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  if ( isset($_POST) AND !empty($_POST) ) {
  $nom = "./config.txt";
  $filez = fopen($nom, "r") or die("Unable to open file!");
  $i = fread($filez,filesize($nom));
  $year = getdate();
  $idy = substr($year[year], 2);
  $fichier = fopen("./resultsrv.txt", "w") or die("Unable to write file!");
      for ($z; $z&lt;$_POST['nbr']+1 ; $z++) {
          $id =  sprintf("%04d", $i+$z); 
          $nome = $_POST['type'].$_POST['OS'].$idy.$id."&lt;br&gt;" ;
          echo $nome;
          $nomewout = str_replace("&lt;br&gt;", ";", $nome);
          fwrite($fichier,$nomewout);
      }
      $handle = fopen("./config.txt", "w") or die("Unable to write file!");
      fwrite($handle,$id);
      fclose($fichier);
      fclose($handle);
  }
  ?&gt;
  </code></pre>
  
  <p>and the one that doesn't work because he doesn't increment :</p>
  
  <pre class="lang-php prettyprint-override"><code>&lt;?php 
  
  if ( isset($_POST) AND !empty($_POST) ) {
  
      $fileName = 'confchass.txt';
      $read = fopen($fileName,"r");
      $fn = fopen($fileName,"w+");
      $i = fread($read,filesize($fileName));
      $id =  sprintf("%03d", $i+1);
  
      echo "&lt;div align='center'&gt;&lt;h1&gt;Le Chassis&lt;/h1&gt;";
      echo $_POST['Marque'].$_POST['DC'].$id;
      echo "&lt;/div&gt;";
      fwrite($fn,$id);
  
      fclose($read);
      fclose($fn);
  
  }
  ?&gt;
  </code></pre>
  
  <p>I want he output a thing like XXXXXX001 and when i refresh or do a new POST from my forms he output XXXXXX002 and XXXXXX003 .... But he actualy output only XXXXXX001</p>