Get Website Lowest price!

Wordpress Experts!

×

php up to date

PHP File Upload

PHP File Upload

PHP File Upload into Folder

<?php       
     $file_name= $_FILES['attachment']['name']; //Get Name Of the Uploaded File
     $extension = end(explode('.', $file_name)); //Get The Extension
     $imagearray=array('gif','png','jpg');
     if(in_array($extension,$imagearray))
     {
      $folder = "upload/";
     }
     else
     {
      $folder= "files/";
     }
     $filePath = $folder. $file_name;
     $tmpName = $_FILES['attachment']['tmp_name'];
     $allowed =  array('gif','png' ,'jpg', 'pdf', 'txt');  //Allowed File Type
     $ext = pathinfo($file_name, PATHINFO_EXTENSION);
     //$_FILES["attachment"]["size"];
     if(!in_array($ext,$allowed) ) {
     echo 'error';
     exit;
     }
     if($_FILES["attachment"]["size"] < 350000) //Set Upload Limit
     {
       $result = move_uploaded_file($tmpName, $filePath); //Move File to the Folder
     }
     else
     {
        echo 'Only file size under 350kb will be upload';
     }
    ?>