File uploaded code-with-validation-PHP




 PHP File uploaded code-with-IMAGE EXTENSION Validation


<?php
 session_start();
 include "include/connection.php";
 include "include/functions.php";
 $userId=$_SESSION['userId'];
 if(!isset($_SESSION['userId'])){
  header("Location:index.php");    
 }
 $prof_type=@$_REQUEST['tp'];
 $msg='';

 if(isset($_POST['subProfileImage']))
 {
  $extArray=array("jpg","jpeg","png","gif");    
  $profImageName=$_FILES['profImage']['name'];
  $fileSize=$_FILES['profImage']['size'];
  $ext =strtolower(pathinfo($profImageName, PATHINFO_EXTENSION));
 
  if($profImageName=='')
  {
      $msg='Please select an image';
  }
  else if(!in_array($ext,$extArray))
  {
     $msg="Please select 'jpg','jpeg','png','gif' type image extension";
  }
  else if($fileSize > 13072400)
  {
    //$msg='Please select image size lessthan 300kb';
  }
  else{
    $imageName=time().$_FILES['profImage']['name'];
    if(move_uploaded_file($_FILES['profImage']['tmp_name'],"upload/prof_photo/".$imageName))
    {
      $oldImgLink=getProfImageLink($userId);  
      $sql="update `user_profile` set `imageLink`='$imageName' where `userId`='$userId'";
      mysql_query($sql);
      @unlink("upload/prof_photo/".$oldImgLink);
    }    
  }    
 }

 $sql_prof="select * from `user_profile` where `userId`='$userId' ";
 $res_prof=mysql_query($sql_prof);
 $r_prof=mysql_fetch_array($res_prof);


 ?>





HTML   form



 <form name="profImageForm" id="profImageForm" action="" method="post" enctype="multipart/form-data">
<h3 id="myModalLabel">Change Profile Pictute</h3>
</div>
<div class="modal-body">
<p>
 <input class="btn btn-primary" type="file" name="profImage" placeholder="Browse for File">
</p>
</div>
<div class="modal-footer">
<input type="hidden" name="tab" id="tabProfileType"  value="<?php echo $prof_type;  ?>" />
<input type="hidden" name="subProfileImage" id="subProfileImage" value="subProfile" />
<button class="btn btn-primary" onClick="return profImageSubmit()">Save changes</button>
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</form>
</div>
</div>
     <div class="span7">
       <div id="personalDetails" style="display:<?php echo $t = ($prof_type=="") ? "none" : "none" ; ?>;" >
         <form class="form-horizontal" name="profileForm" id="profileForm" action="#" method="post">
          <!-- <input type="hidden" name="persionalStatus" id="persionalStatus" value="<?php //echo $r_prof['status'];  ?>" >-->
           <legend>Your Contact Information</legend>
           <div class="control-group">
             <label class="control-label" for="inputEmail">First Name</label>
             <div class="controls">
               <input type="text" name="fname" id="p_fname" value="<?php echo $r_prof['firstName']; ?>" placeholder="Full Name">
             </div>
           </div>
           <div class="control-group">
             <label class="control-label" for="inputEmail">Last Name</label>
             <div class="controls">
               <input type="text" name="lname" id="p_lname" value="<?php echo $r_prof['lastName']; ?>"  placeholder="Last Name">
             </div>
           </div>
           <!--<div class="control-group">
             <label class="control-label" for="inputEmail">Nickname</label>
             <div class="controls">
               <input type="text" name="nickname" id="p_nname" value="<?php //echo $r_prof['nickName']; ?>"  placeholder="Nickname">
             </div>
           </div>-->
           <div class="controls">
             <div class="radio">
               <label>
                 <input type="radio" name="gender" id="p_gender" value="m" <?php if($r_prof['gender']=='m'){ echo 'checked'; }?> >
                 Male</label>
             </div>
             <div class="radio">
               <label>
                 <input type="radio" name="gender" id="p_gender" value="f"  <?php if($r_prof['gender']=='f'){ echo 'checked'; }?>>
                 Female</label>
             </div>
           </div>
           <p></p>
           <div class="control-group">
             <label class="control-label" for="inputEmail">Date of Birth</label>
             <div class="controls">
               <input type="text" name="dob" id="p_dob" value="<?php echo getRevDate($r_prof['dob']); ?>"  placeholder="DOB">
             </div>
           </div>
           <div class="control-group">
             <label class="control-label" for="inputEmail">Mobile No</label>
             <div class="controls">
               <input type="text" name="phoneNo" id="p_phoneNo" value="<?php echo $r_prof['phoneNo']; ?>"  placeholder="Mobile No">
             </div>
           </div>
           <div class="control-group">
             <label class="control-label" for="inputPassword">Capital City</label>
             <div class="controls">
               <select name="capital_city" id="p_capital_city" onChange="return getLocalityList()">
                 <option value="">Select capital city</option>
                  <?php echo getCapitalCityList($r_prof['capital_city']);  ?>
                </select>
             </div>
           </div>
           <div class="control-group">
             <label class="control-label" for="inputPassword">Locality</label>
             <div class="controls">
               <select name="locality" id="p_locality">
                <option value="">Select locality</option>
                  <?php  echo getLocalityList($r_prof['capital_city'],$r_prof['locality']);  ?>
                </select>
             </div>
           </div>
           <div class="btn-group" >
             <input type="hidden" name="updateProf" id="updateProf" value="updateProf" />
             <button type="submit" class="btn btn-primary" id="" onClick="return submitProfile()">Submit</button>
             <button type="reset" class="btn">Reset</button>
             <!--<button type="reset" class="btn">Cancel</button>-->
           </div>
         </form>