Online Photo Gallery - Multi file uploads

Hello, i have this code to login and upload images, and to show a Photo Gallery. But i can only upload one file at a time. I need help changing this code so i can upload multiple images.
Thank you.

<?php
   error_reporting(0);
   $images_folder = "./images/";
   $columns = 4;
   $thumbnail_size = 240;
   $max_photo_size = 4194304;
   $mysql_server = '**********';
   $mysql_username = '*********';
   $mysql_password = '**********';
   $mysql_database = '**************';
   $mysql_table = 'PHOTO_GALLERY';
   $admin_password = isset($_COOKIE['OnlinePhotoGallery']) ? $_COOKIE['OnlinePhotoGallery'] : '';
   $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
   $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : -1;
   $timestamp = date("y-m-d H:i:s", time());

   if (empty($admin_password))
   {
      if (isset($_POST['admin_password']))
      {
         $admin_password = md5($_POST['admin_password']);
         if ($admin_password == md5('************'))
         {
            setcookie('OnlinePhotoGallery', $admin_password, time()+3600);
         }
      }
   }

   $authorized = ($admin_password == md5('patrik&1342'));
   $db = mysql_connect($mysql_server, $mysql_username, $mysql_password);
   if (!$db)
   {
      die('Failed to connect to database server!<br>'.mysql_error());
   }
   mysql_select_db($mysql_database, $db) or die('Failed to select database<br>'.mysql_error());

   if ($authorized)
   {
      $sql = "CREATE TABLE IF NOT EXISTS $mysql_table (id INT UNSIGNED NOT NULL AUTO_INCREMENT,
              wwb_index INT NOT NULL,
              wwb_title VARCHAR(255) NOT NULL,
              wwb_description VARCHAR(255),
              wwb_keywords VARCHAR(255),
              wwb_filename VARCHAR(50) NOT NULL,
              wwb_date TIMESTAMP NOT NULL,
              PRIMARY KEY(id));";
      $result = mysql_query($sql, $db);
      if (!$result)
      {
         die('Invalid query: ' . mysql_error());
      }
      if ($action == 'logout')
      {
         setcookie('OnlinePhotoGallery', '');
         unset($_COOKIE['OnlinePhotoGallery'], $admin_password);
         header("Location: ".basename(__FILE__));
         exit;
      }
      else
      if ($action == 'save')
      {
         $filename = "";
         if (isset($_FILES['filename']) && $_FILES['filename']['name'] != "")
         {
            if (!file_exists($images_folder))
            {
               if (!mkdir($images_folder, 0777))
               {
                  die("Failed to create images directory.");
               }
            }
            if (!file_exists($images_folder ."thumbnails/"))
            {
               if (!mkdir($images_folder ."thumbnails/", 0777))
               {
                  die("Failed to create thumbnail directory.");
               }
            }
            $error_msg = "";
            $name = $_FILES['filename']['name'];
            $type = $_FILES['filename']['type'];
            $tmp_name = $_FILES['filename']['tmp_name'];
            $error = $_FILES['filename']['error'];
            $size = $_FILES['filename']['size'];
            switch ($error)
            {
            case 0:
               if ($type == 'image/gif' || $type == 'image/jpeg' || $type == 'image/pjpeg' || $type == 'image/png' || $type == 'image/x-png')
               {
                  if ($size <= $max_photo_size)
                  {
                     if (!move_uploaded_file($tmp_name, $images_folder . $name))
                     {
                        $error_msg = "Error: Upload failed, please verify the folder's permissions.";
                     }
                     else
                     {
                        $filename = $name;
                     }
                  }
                  else
                  {
                     $error_msg = "Error: The image is too big.";
                  }
               }
               else
               {
                  $error_msg = "Error: Wrong file type, please only use jpg, gif or png images.";
               }
               break;
            case 1:
               $error_msg = "Error: The uploaded file exceeds the 'upload_max_filesize' directive.";
               break;
            case 2:
               $error_msg = "Error: The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
               break;
            case 3:
               $error_msg = "Error: The uploaded file was only partially uploaded.";
               break;
            case 4:
               $error_msg = "Error: No file was uploaded.";
               break;
            case 6:
               $error_msg = "Error: Missing a temporary folder.";
               break;
            case 7:
               $error_msg = "Error: Failed to write file to disk.";
               break;
            case 8:
               $error_msg = "Error: File upload stopped by extension.";
               break;
            }
            if ($error_msg != "")
            {
               die($error_msg);
            }
            list($width, $height, $image_type) = getimagesize($images_folder . $name);
            $image_ratio = $width/$height;
            if ($image_ratio > 0)
            {
               $thumbnail_width = $thumbnail_size;
               $thumbnail_height = 160;
            }
            else
            {
               $thumbnail_width = $thumbnail_size;
               $thumbnail_height = 160;
            }
            $thumbnail_image = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
            switch ($image_type)
            {
            case IMAGETYPE_JPEG:
               $source_image = imagecreatefromjpeg($images_folder . $name);
               break;
            case IMAGETYPE_PNG:
               $source_image = imagecreatefrompng($images_folder . $name);
               break;
            default:
               $source_image = imagecreatefromgif($images_folder . $name);
               break;
            }
            imagecopyresampled($thumbnail_image, $source_image, 0, 0, 0, 0, $thumbnail_width, $thumbnail_height, $width, $height);
            $thumbnail_name = $images_folder ."thumbnails/" . "tn_" . $name;
            switch ($image_type)
            {
            case IMAGETYPE_JPEG:
               imagejpeg($thumbnail_image, $thumbnail_name, 100);
               break;
            case IMAGETYPE_PNG:
               imagepng($thumbnail_image, $thumbnail_name);
               break;
            default:
               imagegif($thumbnail_image, $thumbnail_name);
               break;
            }
         }
         $title = get_magic_quotes_gpc() ? trim($_POST['title']) : addslashes(trim($_POST['title']));
         $title = str_replace("\\\\'", "'", $title);
         $description = get_magic_quotes_gpc() ? trim($_POST['description']) : addslashes(trim($_POST['description']));
         $description = str_replace("\\\\'", "'", $description);
         $keywords = get_magic_quotes_gpc() ? trim($_POST['keywords']) : addslashes(trim($_POST['keywords']));
         $keywords = str_replace("\\\\'", "'", $keywords);
         if ($id >= 0)
         {
            $sql = "UPDATE $mysql_table SET `wwb_title` = '$title', `wwb_description` = '$description', `wwb_keywords` = '$keywords', `wwb_date` = '$timestamp'";
            if ($filename != "")
            {
               $sql .= ", `wwb_filename` = '$filename'";
            }
            $sql .= " WHERE `id` = '$id'";
            mysql_query($sql, $db);
         }
         else
         {
            $sql = "SELECT * FROM $mysql_table";
            $result = mysql_query($sql, $db);
            $wwb_index = mysql_num_rows($result);
            $wwb_index = $wwb_index + 1;
            $sql = "INSERT $mysql_table (`wwb_index`, `wwb_date`, `wwb_filename`, `wwb_title`, `wwb_description`, `wwb_keywords`) VALUES ($wwb_index, '$timestamp', '$filename', '$title', '$description', '$keywords')";
            mysql_query($sql, $db);
         }
         $id = -1;
      }
      else
      if ($action == 'delete')
      {
         $sql = "SELECT * FROM $mysql_table WHERE `id` = '$id'";
         $result = mysql_query($sql, $db);
         if ($data = mysql_fetch_array($result))
         {
            $wwb_index = $data['wwb_index'];
         }
         $sql = "DELETE FROM $mysql_table WHERE `id` = '$id'";
         mysql_query($sql, $db);
         $sql = "UPDATE $mysql_table SET wwb_index=wwb_index-1 WHERE wwb_index > '$wwb_index'";
         mysql_query($sql, $db);
         $id = -1;
      }
   }
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WWB - Online Photo Gallery</title>
<meta name="generator" content="FCAB-Web">
<link rel="stylesheet" href="./prettyPhoto/css/prettyPhoto.css">
<script src="./prettyPhoto/js/jquery.prettyPhoto.js"></script>
<script>
$(document).ready(function()
{
<?php
$lightbox = '$("a[rel^=\\'prettyPhoto_OnlinePhotoGallery\\']").prettyPhoto({theme:\\'facebook\\',social_tools:false});';
if (empty($action) && !$authorized)
{
   echo $lightbox . "\\r\
";
}
?>
});
</script>
</head>
<body>
<center><h1>RS Western Riding - Fotoalbum</h1></center>
<div id="container">
<div id="OnlinePhotoGallery" style="position:absolute;overflow:auto;left:100px;top:0px;width:1200px;height:825px;z-index:0">

<?php
   if ($action == 'admin')
   {
      echo "<form method=\\"post\\" action=\\"" .basename(__FILE__) . "\\">\
";
      echo "<input type=\\"password\\" name=\\"admin_password\\" size=\\"20\\" style=\\"height:26px;\\">\
";
      echo "<input class=\\"admin_login_button\\" type=\\"submit\\" value=\\"Logga in\\" name=\\"submit\\">\
";
      echo "</form>\
";
   }
   else
   if ($action == 'edit' || $action == 'new')
   {
      if ($authorized)
      {
         $title = '';
         $description = '';
         $keywords = '';
         if ($id >= 0)
         {
            $sql = "SELECT * FROM $mysql_table WHERE id = '".$id."'";
            $result = mysql_query($sql, $db);
            if ($data = mysql_fetch_array($result))
            {
               $title = $data['wwb_title'];
               $description = $data['wwb_description'];
               $keywords = $data['wwb_keywords'];
            }
         }
         echo "<form enctype=\\"multipart/form-data\\" action=\\"" .basename(__FILE__) . "\\" method=\\"POST\\">\
";
         echo "<table width=\\"100%\\" cellpadding=\\"0\\" cellspacing=\\"4\\" border=\\"0\\">\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Titel:</span></td><td><input type=\\"text\\" name=\\"title\\" value=\\"" .$title. "\\" size=\\"40\\"></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Beskrivning:</span></td><td><textarea name=\\"description\\" cols=\\"40\\" rows=\\"4\\">" .$description. "</textarea></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Nyckel ord:</span></td><td><input type=\\"text\\" name=\\"keywords\\" value=\\"" .$keywords. "\\" size=\\"40\\"></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td><span class=\\"label\\">Filnamn:</span></td><td><input type=\\"file\\" name=\\"filename\\" multiple=\\"multiple\\" size=\\"1\\"></td>\
";
         echo "</tr>\
";
         echo "<tr>\
";
         echo "<td></td><td align=\\"left\\">\
";
         echo "   <input type=\\"hidden\\" name=\\"action\\" value=\\"save\\">\
";
         echo "   <input type=\\"hidden\\" name=\\"id\\" value=\\"" . $id . "\\">\
";
         echo "   <input type=\\"submit\\" value=\\"Ladda upp\\">\
";
         echo "   <input type=\\"button\\" value=\\"Tillbaka\\" onclick=\\"window.location='" .basename(__FILE__) . "'\\">\
";
		 echo "</td>\
";
         echo "</tr>\
";
         echo "</table>\
";
         echo "</form>\
";
		
      }
   }
   else
   if ($id >= 0)
   {
      $sql = "SELECT * FROM $mysql_table WHERE id='$id'";
      $result = mysql_query($sql, $db);
      if ($data = mysql_fetch_array($result))
      {
         $image_name = $images_folder . $data['wwb_filename'];
         echo "<img alt=\\"\\" style=\\"margin:10px\\" border=\\"0\\" src=\\"$image_name\\">\\r\
";
      }
   }
   else
   {
      if ($authorized)
      {
         echo "<a class=\\"file_button\\" href=\\"".basename(__FILE__)."?action=new\\">  Välj fil/filer...  </a>  ";
         echo "<a class=\\"logout_button\\" href=\\"".basename(__FILE__)."?action=logout\\">    Logga ut    </a><br><br>\
";
      }
      $sql = "SELECT * FROM $mysql_table";
      if (isset($_GET['q']))
      {
         $terms = explode(" ", urldecode($_GET['q']));
         $sql .= " WHERE `wwb_keywords` LIKE '%";
         $sql .= $terms[0];
         $sql .= "%'";
         for ($i=1; $i<count($terms); $i++)
         {
            $sql = $sql. " AND `wwb_keywords` LIKE '%". $terms[$i] . "%'";
         }
      }
      $sql .= " ORDER BY wwb_date DESC";
      $result = mysql_query($sql, $db);
      echo "<table border=\\"0\\" cellspacing=\\"20\\" cellpadding=\\"0\\">\\r\
";
      echo "<tr>\\r\
";
      $counter = 1;
      while ($data = mysql_fetch_array($result))
      {
         $thumbnail = $images_folder . "thumbnails/tn_" . $data['wwb_filename'];
         echo "<td align=\\"center\\" valign=\\"bottom\\">\\r\
";
         echo "   <a href=\\"" . $images_folder . $data['wwb_filename'] . "\\" rel=\\"prettyPhoto_OnlinePhotoGallery[OnlinePhotoGallery]\\" title=\\"". $data['wwb_title'] . "\\">";
         echo "<img alt=\\"\\" src=\\"$thumbnail\\" border=\\"0\\"></a><br>";
         //echo "<span class='title'>" . $data['wwb_title'] . "</span><br>\\r\
";
         if ($authorized)
         {
            echo "   <table cellpadding=\\"0\\" cellspacing=\\"0\\" border=\\"0\\">\
";
            echo "   <tr>\
";
            echo "   <td>\
";
            echo "      <form action=\\"" .basename(__FILE__) . "\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"action\\" value=\\"edit\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"id\\" value=\\"" . $data['id'] . "\\">\
";
            echo "      <input type=\\"submit\\" value=\\"Ändra\\">&nbsp\
";
            echo "      </form>\
";
            echo "   </td>\
";
            echo "   <td>\
";
            echo "      <form action=\\"" .basename(__FILE__) . "\\" onSubmit=\\"return confirm('Radera - Är du säker?')\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"action\\" value=\\"delete\\">\
";
            echo "      <input type=\\"hidden\\" name=\\"id\\" value=\\"" . $data['id'] . "\\">\
";
            echo "      <input type=\\"submit\\" value=\\"Radera\\">\
";
            echo "      </form>\
";
            echo "   </td>\
";
            echo "   </tr>\
";
            echo "   </table><br>\\r\
";
         }
         echo "</td>\\r\
";
         if ($counter != $columns)
         {
            $counter++;
         }
         else
         {
            echo "</tr>\\r\
<tr>\
";
            $counter = 1;
         }
      }
      if ($counter != 1)
      {
         while ($counter <= $columns)
         {
            echo "<td> </td>\\r\
";
            $counter++;
         }
      }
      echo "</tr>\\r\
";
      echo "</table>\\r\
";
      if (!$authorized)
      {
         echo "<a class=\\"logout_button\\" href=\\"".basename(__FILE__)."?action=admin\\">  Admin login  </a>";
      }
   }
?>
</div>
</div>
</body>
</html>

Oops. sorry wrong place for this i think, moved it to PHP section.