title: Making directory in php
body: <p>I have a problem when I want to upload pictures and to make new directory which does not exist it doesnt make folder $gallery_name, it store pictures in uploads/galerije/$username instead of uploads/galerije/$username/$gallery_name.
  Can anyone help me?</p>
  
  <pre><code>$username = $_SESSION['username'];
  $gallery_name = $_POST['gallery_name'];
  
  if (isset($_FILES['files'])) {
      $errors = array();
      foreach ( $_FILES['files']['tmp_name'] as $key =&gt; $tmp_name ) {
          $file_name = $key . $_FILES['files']['name'][$key];
          $file_size = $_FILES['files']['size'][$key];
          $file_tmp = $_FILES['files']['tmp_name'][$key];
          $file_type = $_FILES['files']['type'][$key];
  
          if ($file_size &gt; 2097152) {
              $errors[] = 'File size must be less than 2 MB';
          }
  
          $desired_dir = "uploads/galerije/" . $username . "/" . $gallery_name;
  
          if (empty($errors)) {
              if (!is_dir($desired_dir)) {
                  mkdir($desired_dir, 0777); // Create directory if it does not exist
              }
              if (!is_dir("$desired_dir/" . $file_name) == false) {
                  move_uploaded_file($file_tmp, "$desired_dir/" . $file_name);
                  header("location: index.php");
              }
          }
          else {
              print_r($errors);
          }
      }
      if (empty($error)) {
          echo "Success";
      }
  }
  </code></pre>