title: Issues putting files into the correct folder
body: <p>I just had another question to follow on from: <a href="https://stackoverflow.com/questions/17073341/putting-php-array-into-mysql-with-additional-columns/17073559?noredirect=1#17073559">Putting PHP array into MySQL with additional columns</a></p>
  
  <p>I am trying to put the files into separate folders depending on the extension. However, the files end up in the same folder with the same file name regardless of what the array shows when I print it out.</p>
  
  <p>This is the array that I have at the moment:</p>
  
  <pre><code>$files[$key] = array
  (
      $file_name = basename($guid." - ".$_FILES['file']['name'][$key]),
      $file_type = $_FILES['file']['type'][$key],
      $file_size = $_FILES['file']['size'][$key],
      $file_tmp = $_FILES['file']['tmp_name'][$key],
      $extension = strtolower(substr($file_name, strlen($file_name)-4, strlen($file_name))),
      $tgt = $_FILES['file']['name'][$key]
  );
  </code></pre>
  
  <p>This is the array output I have at the moment:</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [0] =&gt; 966c5853-63b4-4570-a3ee-bd5629688038 - cycles.pdf
          [1] =&gt; application/pdf
          [2] =&gt; 331881
          [3] =&gt; C:\xampp\tmp\php9738.tmp
          [4] =&gt; .pdf
          [5] =&gt; cycles.pdf
      )
  
  [1] =&gt; Array
      (
          [0] =&gt; 966c5853-63b4-4570-a3ee-bd5629688038 - landofstoopid.bmp
          [1] =&gt; image/bmp
          [2] =&gt; 310342
          [3] =&gt; C:\xampp\tmp\php9758.tmp
          [4] =&gt; .bmp
          [5] =&gt; landofstoopid.bmp
      )
  </code></pre>
  
  <p>)</p>
  
  <p>This is the SQL query generation that I have:</p>
  
  <pre><code>$new = array();
  foreach($files as $key =&gt; $value)
  {
      $new[] = "'".implode("','", $value)."', '$guid', '$getthedate', '$gettime', '$mailid', '$target'";
  }
  $query = "(".implode("), (",$new).")";
  </code></pre>
  
  <p>This is the output from the SQL query</p>
  
  <pre><code>INSERT INTO files (filename, filetype, filesize, filetempname, guid, dateadded, timeadded, mailid, target) 
  VALUES ('966c5853-63b4-4570-a3ee-bd5629688038 - cycles.pdf','application/pdf','331881','C:\xampp\tmp\php9738.tmp','.pdf','cycles.pdf', '966c5853-63b4-4570-a3ee-bd5629688038', '13 Jun 2013', '10:25:07', '77', 'files/pics/landofstoopid.bmp'), 
  ('966c5853-63b4-4570-a3ee-bd5629688038 - landofstoopid.bmp','image/bmp','310342','C:\xampp\tmp\php9758.tmp','.bmp','landofstoopid.bmp', '966c5853-63b4-4570-a3ee-bd5629688038', '13 Jun 2013', '10:25:07', '77', 'files/pics/landofstoopid.bmp')
  </code></pre>
  
  <p>This is what I have to determine where the file should be placed</p>
  
  <pre><code>$pics = array(".bmp", ".gif", ".jpg", "jpeg", ".png"); //5              
  $docs = array(".doc", "docx", ".odt", ".pdf", ".ppt", "pptx", ".rtf", ".txt", ".xls", "xlsx"); //10             
  $misc = array(".csv", ".htm", "html", ".php", ".pkt", ".rar", ".sql", ".xpi", ".zip"); //9
  
  if (in_array($extension,$pics))
  {
      $target = "".FILES."/".FUP_PICS."/";
  }
  else if (in_array($extension,$docs))
  {
      $target = "".FILES."/".FUP_DOCS."/";
  }
  else if (in_array($extension,$misc))
  {
      $target = "".FILES."/".FUP_MISC."/";
  }
  $target = $target.$tgt;
  </code></pre>
  
  <p>I have tried this both inside the foreach loop to get the values of the multiple files and outside of it and it ends up the same way.</p>
  
  <p>The target for the files is always determined on the last filename and extension. As above, I have a .pdf and a .bmp and the pdf should go in the docs folder and the bmp should go in the pics folder. However, both files are being sent to pics folder and the name changed to the last file in the array.</p>
  
  <p>Just wondering if I could get some pointers as to where I am going wrong, or if this is even possible.</p>
  
  <p>I will add, that when the file is uploaded as a single file this issue does not occur and the file goes to the right folder.</p>
  
  <p>Thanks in advance</p>