title: Php create a file if not exists
body: <p>I try to create files and write the contents dynamically. Below is my code.</p>
  
  <pre><code>$sites = realpath(dirname(__FILE__)).'/';
  $newfile = $sites.$filnme_epub.".js";
  
  if (file_exists($newfile)) {
      $fh = fopen($newfile, 'a');
      fwrite($fh, 'd');
  } else {
      echo "sfaf";
      $fh = fopen($newfile, 'wb');
      fwrite($fh, 'd');
  }
  
  fclose($fh);
  chmod($newfile, 0777);
  
  // echo (is_writable($filnme_epub.".js")) ? 'writable' : 'not writable';
  echo (is_readable($filnme_epub.".js")) ? 'readable' : 'not readable';
  die;
  </code></pre>
  
  <p>However, it does not create the files.</p>
  
  <p>Please share your answers and help. Thanks!</p>