title: fwrite() expects parameter 1 to be resource, string given in c://
body: <p>I am using latest version of php.. and i stuck on this error </p>
  
  <blockquote>
    <p>Warning: fwrite() expects parameter 1 to be resource, string given in c:\ this error shows me 6 times</p>
    
    <p>Warning: fclose() expects parameter 1 to be resource, string given in  // this error reapeat only one time.</p>
  </blockquote>
  
  <p>I am trying to get last id  of last line but i am facing that error.. here is my php code :</p>
  
  <pre><code>&lt;?php
  include_once('../../fucrenzione.php');
  /*
  $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
  $codeAlphabet.= "0123456789";*/
  $filename ="data.txt" or die("Unable to open file!");
  $line="";
  fopen($filename, 'a+');
      for($i=0;$i&lt;=5;$i++ ){
  
          $va=rand(1,20);
          $re= rand(2,50);
          $data = [
                  'val1' =&gt; $va,
                  'val2' =&gt; $re, 
                  'body' =&gt; getToken(10),
                  'Id'=&gt; $i,
                  'timestamp' =&gt; time()
                  ];
  
       /* echo   "&lt;pre&gt;".*/$line = serialize($data);
       $line .= "\n";
      fwrite($filename, $line);
  
      }
  fclose($filename);
  ?&gt;
  </code></pre>
  
  <p>I tried to use also <code>fputs()</code> but i still get that error.</p>