title: PHP - Upload multiple photos into newly created Directory
body: <p>I've been digging for an answer for days now in how to upload multiple photos into a database without overloading the system, and decided the best way is to upload multiple photos into a newly created directory (created via php) and store the directory link in the  database instead. What I'm working on is a form that basically creates a new unique page. This unique page has a unique set of photos, and hence I need to generate a folder each time a page is generated, and upload the path link to the database! How do I do that???</p>
  
  <p>Here is my HTML:</p>
  
  <pre><code>&lt;form method="post" action="test.php" enctype="multipart/form-data"&gt;
    &lt;p&gt;File:&lt;/p&gt;
    &lt;input type="file" name="file[]" id="file" &gt;
    &lt;input type="submit" value="Upload"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and here is my PHP so far (should be on the right track I hope :/):</p>
  
  <pre><code>&lt;?php
    //Connect to DB
    $conn = mysql_connect ('localhost', 'root', 'root');
    if (!$conn){
      die("Could Not Connect to MySQL!");
    }
    if(!mysql_select_db("test")){
      die("Could Not Open Database:" . mysql_error());
    }
    echo "&lt;p&gt;Connected&lt;/p&gt;";
  
    //Upload Files
    foreach ($_FILES['file']['name'] as $f =&gt; $name) {
      $allowedExts = array("gif", "jpeg", "jpg", "png");
      $temp = explode(".", $name);
      $extension = end($temp);
  
      if ((($_FILES["file"]["type"][$f] == "image/gif")
      || ($_FILES["file"]["type"][$f] == "image/jpeg")
      || ($_FILES["file"]["type"][$f] == "image/jpg")
      || ($_FILES["file"]["type"][$f] == "image/png"))
      &amp;&amp; ($_FILES["file"]["size"][$f] &lt; 2000000)
      &amp;&amp; in_array($extension, $allowedExts))
      {
        if ($_FILES["file"]["error"][$f] &gt; 0){
          echo "Return Code: " . $_FILES["file"]["error"][$f] . "&lt;br&gt;";
        } else {
          if (file_exists("uploads/" . $name)){
            echo "&lt;p&gt;File Already Exists&lt;/p&gt;";
          } else {
            //create new directory folder within /uploads
  
            //move the files you upload into the new folder.
            move_uploaded_file($_FILES["file"]["tmp_name"][$f], "upload/" . uniqid() . "_" . $name);
            //send the file path to the database.
            mysql_query("INSERT INTO test (idtest,testing) VALUES (','{$filepath}'");
          }
        }
      } else {
        $error =  "Invalid file";
      }
    }
  ?&gt;
  </code></pre>
  
  <p>and for those curious, here is my database collumns:</p>
  
  <pre><code>|| idtest (AI, INT) || testing (varchart(50)) ||
  </code></pre>
  
  <p>Any help is IMMENSELY appreciated! It's been doing me in! Thank you in advance!</p>