title: What will be the easiest java code for a file upload in server
body: <p>I am using following PHP code to upload file from client side to server with some conditions.<br/>
  - One file at a time and file size less than 35mb.<br/>
  - File only support "jpeg", "jpg", "png", "wav", "mp3" format.<br/>
  - Every file must upload in a only 10 digit's name folder, given by client during file's upload (if this folder name already present,the file will automatically upload inside the present folder, without making any new folder)<br/></p>
  
  <pre><code>&lt;?php
  error_reporting(0);
   if(isset($_FILES['image'])){
    $errors= array();
    $file_name = $_FILES['image']['name'];
    $file_size =$_FILES['image']['size'];
    $file_tmp =$_FILES['image']['tmp_name'];
    $file_type=$_FILES['image']['type'];   
    $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
  
    $expensions= array("jpeg","jpg","png","wav","mp3");   
    if(in_array($file_ext,$expensions)=== false){
     $errors[]="extension not allowed, please choose a JPEG or PNG file.";
    }
    if($file_size &gt; 34097152){
    $errors[]='File size must be exactly 34 MB';
    }    
    if(empty($errors)==true){
     $pinCode = $_POST['pinc'].".".$file_ext;
     if(move_uploaded_file($file_tmp,$_POST['pinc']."/".$file_name))
     {
  /*     if(rename("mobile/".$file_name,"mobile/".$mobile number))*/
       echo "Success";
     }
     else
     {
     if (mkdir($_POST['pinc'])) {
                        move_uploaded_file($file_tmp,$_POST['pinc']."/".$file_name);
               } else
               {
                        die('Failed to create folders...'); 
                }
  
     }
    }else{
     print_r($errors);
    }
   }
  ?&gt;
  
  &lt;form action="" method="POST" enctype="multipart/form-data"&gt;
  &lt;table width="100%" border="0" align="center"&gt;
    &lt;tr&gt;
      &lt;td width="30%" align="right"&gt;&lt;strong&gt;mobilenumber &lt;/strong&gt;&lt;/td&gt;
      &lt;td width="22%"&gt;&lt;input type="text" name="pinc" value="" /&gt;&lt;/td&gt;
      &lt;td width="48%"&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&lt;input type="file" name="image" /&gt;
  &lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td&gt;&lt;input type="submit"/&gt;&lt;/td&gt;
      &lt;td&gt;&amp;nbsp;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>I try to make it in Java + Http.</strong> I am not so good at java but still I worked out few parts (you can see it in <a href="http://jsfiddle.net/sNxh8/" rel="nofollow">jsfiddle.net/sNxh8</a>) but get trap where I have to submit the form after checking the 3 conditions. A little guideline will be appreciated. Thanks in advance<br/>The result will be like this (http:/ /www.sitename.com/mobile/client's_10_digits_folder_name/file.mp3).</p>