title: PHP create and write form
body: <p>I have a form with two fields. The first textbox the users enter information into is what I would like to name the file that is being saved, and the second textarea is for what I would like written into the file. I am able to write to a file I have already created using php coding below which I did simply to test the function:</p>
  
  <pre><code>&lt;?php
  
  //  If a session already exists, this doesn't have any effect.
  session_start();
  
  //  Sets the current directory to the directory this script is running in
  chdir(dirname(__FILE__));
  
  //  Breakpoint
  if( empty($_SESSION['username']) || $_SESSION['username'] == '' ) echo 'There is no session username';
  if( empty($_POST['CodeDescription']) || $_POST['CodeDescription'] == '' ) echo 'There is no POST CodeDescription';
  
  //  Get current working directory
  echo getcwd();
  //  This should output   /home/revo/public_html/evo/users
  
  //  This is assuming we are working from the current directory that is running this PHP file.
  $USER_DIRECTORY = 'users/'.$_SESSION['username'];
  
  //  Makes the directory if it doesn't exist
  if(!is_dir($USER_DIRECTORY)):
  mkdir($USER_DIRECTORY);
  endif;
  
  //  Put together the full path of the file we want to create
  $FILENAME = $USER_DIRECTORY.'/'.$_POST['CodeDescription'].'.txt';
  
  if( is_file( $FILENAME ) ):
  
  // Open the text file
    $f = fopen($FILENAME, "w");
  
  // Write text
    file_put_contents($FILENAME, $_POST['Code']); 
  
  // Close the text file
    fclose($f);
  
  // Open file for reading, and read the line
    $f = fopen($FILENAME, "r");
  
  else:
  
  echo 'Filename already exists';
  
  endif;
  
  ?&gt;
  </code></pre>
  
  <p>However I am unsure how to check to see if a file with the name they enter into the first box exists, and then if not create it, then write the information from the second box into the file.</p>