title: How to create directory dynamically?
body: <p>I have the code below but I want to write the file under a dynamically created folder from date. So it should look like this date/filename.txt</p>
  
  <pre><code>   &lt;?php
      if(isset($_POST['field1']) &amp;&amp; isset($_POST['field2'])) {
          $data = $_POST['field1'] . '-' . $_POST['field2'] . "\n";
          $filename = date('YmdHis').".txt";
          if (!file_exists($filename)) {
              $fh = fopen($filename, 'w') or die("Can't create file");
          }
          $ret = file_put_contents($filename, $data, FILE_APPEND | LOCK_EX);
          if($ret === false) {
              die('There was an error writing this file');
          }
          else {
              echo "$ret bytes written to file";
          }
      }
      else {
         die('no post data to process');
      }
      ?&gt;
  </code></pre>