title: Create another PHP file with PHP script
body: <p>I need to create a new .php file as MySQL connection configuration file.
  I have a listing like this:</p>
  
  <pre><code>$fileLocation = $_SERVER['DOCUMENT_ROOT'] . "/dbconnect.php";
  file_put_contents($fileLocation,$content);
  $content = "&lt;?php $koneksi = mysql_connect('.$host.', '.$username.', '.$password.'); //open connection
  if(! $koneksi ) //if fail
  {
    die(\'Gagal Koneksi: \' . mysql_error());
  }
  echo \'Koneksi Berhasil\'; ?&gt;";
  </code></pre>
  
  <p>I get the <code>$username</code>, <code>$host</code>, and <code>$password</code> from another file (containing form for the host, username, and password) using post method.</p>
  
  <p>And I want to create the file in the root directory, I did that code and it doesn't work. I try <code>fwrite</code> and doesn't work too. I Google it but I'm not really understand what am I reading.</p>
  
  <p>How should I do that?</p>