Thursday, 7 November 2013

File Upload in PHP

Hi there
Uploading file on server is a process of getting data from user. you cannot ignore it and every web developer needs upload file.php has some built in function which helps to upload file take a look on following line..
Control
File up loader
Submit button
Code
<?php
       $msg="";
       if(isset($_POST['submit'])
      {
           if($_FILES['file']['name']!="")
          {
   $extnsn=end(explode(".", strtolower($_FILES['file']['name'])));
    if($extnsn=="rtf" || $extnsn=="doc" || $extnsn=="docx" || $extnsn=="txt" || $extnsn=="pdf")
    {                                                                
              if(($_FILES['file']['size']/1024)>1024)
             {
                      $msg="Sorry ! Maximum upload file  size is  1024 KB";
              }
              else
              {
                     move_uploaded_file($_FILES['file']['tmp_name'],"resume/".$r[0].".".$extnsn);
                      $msg="Thanks for uploading  file";
                      <?php
                             echo $msg;
                      ?>  
                                                  
               }
     }
}

}
?>
<html>
                <head><title>Girfa File upload </title></head>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']?>" enctype="multipart/form-data" >
            <input type="file" name="file" /><br /><span class="qoate">
                <input type="submit" value="Save" name="submit" />

  </form>
</body>
</html>