title: Upload multiple files using PHP
body: <p>I have the following code to upload files to a database in mysql:</p>
  
  <p><strong>Index.php</strong></p>
  
  <pre><code>&lt;?php
  include_once 'dbconfig.php';
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;title&gt;File Uploading With PHP and MySql&lt;/title&gt;
  &lt;link rel="stylesheet" href="style.css" type="text/css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="header"&gt;
    &lt;label&gt;File Uploading With PHP and MySql&lt;/label&gt;
  &lt;/div&gt;
  &lt;div id="body"&gt;
       &lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt;
    &lt;input type="file" name="file" /&gt;
  &lt;button type="submit" name="btn-upload"&gt;upload&lt;/button&gt;
  &lt;/form&gt;
  &lt;br /&gt;&lt;br /&gt;
  
  &lt;?php
  if(isset($_GET['success']))
  {
      ?&gt;
      &lt;label&gt;File Uploaded Successfully...  &lt;a href="view.php"&gt;click here to view file.&lt;/a&gt;&lt;/label&gt;
      &lt;?php
  }
  else if(isset($_GET['fail']))
  {
      ?&gt;
      &lt;label&gt;Problem While File Uploading !&lt;/label&gt;
      &lt;?php
  }
  else
  {
      ?&gt;
  
      &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p><strong>Upload.php</strong></p>
  
  <pre><code>&lt;?php
  include_once 'dbconfig.php';
  if(isset($_POST['btn-upload']))
  {    
  
  $file = rand(1000,100000)."-".$_FILES['file']['name'];
  $file_loc = $_FILES['file']['tmp_name'];
  $file_size = $_FILES['file']['size'];
  $file_type = $_FILES['file']['type'];
  $folder="uploads/";
  
  // new file size in KB
  $new_size = $file_size/1024;  
  // new file size in KB
  
  // make file name in lower case
  $new_file_name = strtolower($file);
  // make file name in lower case
  
  $final_file=str_replace(' ','-',$new_file_name);
  
  if(move_uploaded_file($file_loc,$folder.$final_file))
  {
      $sql="INSERT INTO tbl_uploads(file,type,size) VALUES('$final_file','$file_type','$new_size')";
      mysql_query($sql);
      ?&gt;
      &lt;script&gt;
      alert('successfully uploaded');
      window.location.href='index.php?success';
      &lt;/script&gt;
      &lt;?php
  }
  else
  {
      ?&gt;
      &lt;script&gt;
      alert('error while uploading file');
      window.location.href='index.php?fail';
      &lt;/script&gt;
      &lt;?php
  }
  }
  ?&gt;
  </code></pre>
  
  <p>which works well, but only for individual file. I saw many tutorials, but I can not modify the code to allow upload multiple files at once. Any suggestions?</p>