title: Multiple file upload and store them in a directory
body: <p>I'm trying to upload multiple files and store them into a directory for a specific hotel room.</p>
  
  <p>PHP will check if there is already a directory and if not it will make it. However the part of moving the files to that directory does not work.</p>
  
  <p>My create a room function:</p>
  
  <pre><code>public function create($fields = array(), $file) {
  
      if(!$this-&gt;_db-&gt;insert('rooms', $fields)) {
          throw new Exception('There was a small problem creating the room');
      }
  
      else{
          $roomNR = $fields['roomnr'];
          $dir = $_SERVER['DOCUMENT_ROOT'] . "/images/rooms/$roomNR";
  
          if ( !file_exists($dir) ) {
              mkdir ($dir, 0744);
          }
          move_uploaded_file($file["file"]["tmp_name"], "$dir/" . $file["file"]["name"]);
      }
  }
  </code></pre>
  
  <p>This is how I pass everything to my function:</p>
  
  <pre><code>try{
              $newRoom-&gt;create(array(
                  'roomnr' =&gt; Input::get('roomnr'),
                  'catagory' =&gt; Input::get('Catagory'),
                  ),$_FILES);
  
              Session::flash('success', 'The room has been added');
              // Redirect::to('admin-rooms.php');
  
          } catch(Exception $e){
              die($e-&gt;getMessage());
          }
  </code></pre>
  
  <p>and here is my form that I use:</p>
  
  <pre><code>&lt;form role="form" action="" method="post"&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="roomnumber"&gt;Room Number:&lt;/label&gt;
      &lt;input type="text" name="roomnr" id="roomnumber"&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;label for="Catagory"&gt;Catagory:&lt;/label&gt;
      &lt;select name="Catagory" id="Catagory"&gt;
      &lt;?php 
  
      $catagorys = DB::Getinstance()-&gt;query('SELECT * FROM catagory');
  
      if ($catagorys-&gt;count()) {
          foreach($catagorys-&gt;results() as $catagory){?&gt;
          &lt;option value="&lt;?php echo $catagory-&gt;name; ?&gt;"&gt;&lt;?php echo $catagory-&gt;name; ?&gt;&lt;/option&gt;
  
          &lt;?php }
      }
  
       ?&gt;
          &lt;/select&gt;&lt;br&gt;
  &lt;/div&gt;
      &lt;div&gt;
          &lt;label for="file"&gt;Picture: &lt;/label&gt; &lt;input type="file" name="file" id="file" accept="image/*" multiple&gt;&lt;br&gt;
      &lt;/div&gt;
  &lt;input type="hidden" name="token" value="&lt;?php echo Token::generate(); ?&gt;"&gt;
      &lt;input type="submit" value="Insert"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Sorry if the code is not that clean!</p>
  
  <p>For the people that want to take a look: <a href="https://github.com/rrgraute/Hotel" rel="nofollow">Github</a></p>