title: Upload Multiple File and text using HTML form and PHP
body: <p>hey I'm stuck on a project since long. Well I have a Project in which user upload multiple images and add tile, description. The form is processed, the image files are stored in a folder and creates thumbnails and the same entry is added to the MySQL database. Well I have done the image processing and thumbnail generation using the "<code>foreach ($_FILES as $k=&gt;$v)</code>". But I'm unable to get the same repeat with the text fields (Title and description). Here is the code for both "<code>form.php</code>" and "<code>process.php</code>". Please help.</p>
  
  <p><strong>formprocess.php</strong>:-<br>
      
      
  
  <pre><code>foreach($_FILES as $k =&gt; $v){
    if($_FILES[$k]['size'] &gt; 100000){
      echo "Image size exceeded";
      return false;
    }
    else {
      $add = "../Image_Folder/".$_FILES[$k][name]; // the path with the file name where the file will be stored, upload is the directory name.
      //echo $add;
  
      if(!move_uploaded_file ($_FILES[$k][tmp_name], $add)){
        echo "Failed to upload file Contact Site admin to fix the problem";
        exit;
      }
      else {
        $query = "INSERT INTO Image (img_id, user_id, img_src) VALUES (NULL, '$user_id', '{$_FILES[$k][name]}')";
  
        $result = mysql_query($query);
  
        if(!$result) {
          die('Unable to upload Poster to database: ' . mysql_error());
        }
        else{
          $query2 = mysql_query("SELECT img_id FROM Image WHERE img_id = last_insert_id()") or die(mysql_error());
  
          while($row=@mysql_fetch_array($query2, MYSQL_ASSOC)){
            $cat_id=$row['img_id'];
          }
  
          ///////// Start the thumbnail generation//////////////
          $n_width = 100;          // Fix the width of the thumb nail images
          $n_height = 100;         // Fix the height of the thumb nail imaage
  
          $tsrc = "../Image_thumbs/".$_FILES[$k][name];   // Path where thumb nail image will be stored
          //echo $tsrc;
  
          if (!($_FILES[$k][type] == "image/jpeg" OR $_FILES[$k][type] == "image/gif" OR $_FILES[$k][type] == "image/png")) {
            echo "Your uploaded file must be of JPG or GIF or png. Other file types are not allowed&lt;BR&gt;";
            exit;
          }
  
          ////////////////////// Starting of GIF thumb nail creation ///////////
          if (@$_FILES[$k][type] == "image/gif")
          {
            $im = ImageCreateFromGIF($add);
            $width = ImageSx($im);              // Original picture width is stored
            $height = ImageSy($im);             // Original picture height is stored
            $newimage = imagecreatetruecolor($n_width, $n_height);
            imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
  
            if (function_exists("imagegif")) {
              Header("Content-type: image/gif");
              ImageGIF($newimage, $tsrc);
            }
            elseif (function_exists("imagejpeg")) {
              Header("Content-type: image/jpeg");
              ImageJPEG($newimage, $tsrc);
            }
  
            chmod("$tsrc", 0777);
          }
          ////////// end of gif file thumb nail creation //////////
  
          //// start of png thumb nail creation ////
          if (@$_FILES[$k][type] == "image/png")
          {
            $im = ImageCreateFromGIF($add);
            $width = ImageSx($im);              // Original picture width is stored
            $height = ImageSy($im);             // Original picture height is stored
            $newimage = imagecreatetruecolor($n_width, $n_height);
            imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
  
            if (function_exists("imagepng")) {
              Header("Content-type: image/png");
              ImagePNG($newimage, $tsrc);
            }
            elseif (function_exists("imagejpeg")) {
              Header("Content-type: image/jpeg");
              ImageJPEG($newimage, $tsrc);
            }
  
            chmod("$tsrc", 0777);
          }
          //// end of png thumbnail generation /////
  
          ////////////// starting of JPG thumb nail creation //////////
          if($_FILES[$k][type] == "image/jpeg"){
            $im = ImageCreateFromJPEG($add);
            $width = ImageSx($im);              // Original picture width is stored
            $height = ImageSy($im);             // Original picture height is stored
            $newimage = imagecreatetruecolor($n_width, $n_height);
            imageCopyResized($newimage, $im, 0, 0, 0, 0, $n_width, $n_height, $width, $height);
            ImageJpeg($newimage, $tsrc);
            chmod("$tsrc", 0777);
          }
  
          $sql = "INSERT INTO catalogue_thumb(thumbid, cat_id, thumb_src) VALUES(NULL, '$cat_id', '$tsrc')";
          $result_sql = mysql_query($sql);
          if(!$result_sql){
            echo "Sorry could not save thumbnail to database";
            return false;
          }
          else{
            echo "All Images and Thumbs Uploaded successfully";
          }
        }
      }
    }
  }
  ?&gt;
  &lt;/blink&gt;
  </code></pre>
  
  <p><strong>form.php</strong>:-  </p>
  
  <pre><code>$upload_image_limit = 6;
  while($i++ &lt; $upload_image_limit){
    $form_img .= '&lt;label&gt;Image '.$i.': &lt;/label&gt;
                  &lt;input type="file" name="uplimg'.$i.'"&gt;&lt;br/&gt;
  
                  &lt;label for="name"&gt;Enter Prduct Name&lt;/label&gt;
                  &lt;input type="text" maxlength="65" name="img_name"/&gt;
  
                  &lt;label for="description"&gt;Add Description&lt;/label&gt;
                  &lt;input type="text" maxlength="250" name="img_description"/&gt;
                 ';
  }
  
  $htmo .= '&lt;form method="post" enctype="multipart/form-data" action="formprocess.php"&gt;
              &lt;fieldset&gt;
                '.$form_img.'
                &lt;input type="submit" value="Upload" style="margin-left: 50px;" /&gt;
              &lt;/fieldset&gt;
            &lt;/form&gt;
           ';
  echo $html;
  ?&gt;
  //////////////////////////////////////////////
  </code></pre>