title: can we write and open pdf file using file handling in php
body: <p>I am using file handling in php to create write and then read pdf file. The problem is it creates the pdf file but could not open it, when i open the file it simply says that </p>
  
  <p>"Adobe reader can't open this file because it is either not a supported file type or the file has been damaged (for eg: it was sent as an email attachment and was not correctly decoded)"</p>
  
  <p>MY code is below:</p>
  
  <pre><code>&lt;?php
  $file = "testFile.pdf";
  $fh = fopen($file, 'w') or die("can't open file");
  $stringData = "Bobby Bopper\n";
  fwrite($fh, $stringData);
  $stringData = "Tracy Tanner\n";
  fwrite($fh, $stringData);
  
  header("Cache-control: private");
  header("Content-Type: application/pdf");
  header("Content-Length: ".filesize($file));
  header("Content-Disposition: inline; filename=$file");
  
  readfile($file);
  fclose ($fd);
  ?&gt;
  </code></pre>