title: how to check whether multiple folders exists or not like wordpress style
body: <p>I am using the following PHP code:</p>
  
  <pre><code>if (!file_exists('../products'))
      {
          mkdir('../products', 0777, true);
          $target = "Main Not Present, ";
      }
  else
      {
          if(file_exists('../products'))
              {
                  $timezone = new DateTimeZone("Asia/Kolkata");
                  $datetime = new DateTime();
                  $datetime-&gt;setTimezone($timezone);
  
                  $year = $datetime-&gt;format('Y');
                  $month = $datetime-&gt;format('M');
                  $day = $datetime-&gt;format('D');
                  $timestamp = $datetime-&gt;format('Y-m-d H:i:s');
  
                  if(!file_exists('../products/'.$year))
                      {
                          mkdir('../products/'.$year, 0777, true);
                          $target = $target."With year not present also, ";
                      }
                  else
                      {
                          if(file_exists('../products/'.$year))
                              {
                                  if(!file_exists('../products/'.$year."/".$month))
                                      {
                                          $target = $target."With not not present also";
                                      }
                              }
                      }
              }
      }
  </code></pre>
  
  <p>I am creating an ecommerce website using CMS technique like Wordpress, however i am trying to check whether certain directories exist or not, if they don't then to create them and proceed. The problem with my code is that when this code is encountered true </p>
  
  <pre><code>if (!file_exists('../products'))
  {
      mkdir('../products', 0777, true);
      $target = "Main Not Present, ";
  }
  </code></pre>
  
  <p>it creates the directory and the data is stored in the variable, the problem is that it isn't processing further and going in the else statement whether the other folders in that <code>products</code> folder exists or not.</p>
  
  <p>What I am trying to achieve is that</p>
  
  <p>1.) check the products folder, if it doesn't exists then create if it exists then proceed further, lets take worse case that it isn't present then in this case if i want to create that folder and make my code work further but with this code it only satisfy the 1st if condition and don't go in the else statement to satisfy the code further.</p>
  
  <p>Can anyone help me with this? Thanks in advance.</p>