input file type, upload only selected extension
<p>I have php file to upload different kind of image file like .jpg, .gif an soon but my problem is that i also need to upload file like Microsoft office file like .doc, .docx, and .xlsx  and I can't figure out how to make this thing work with that kind of extension, also video and music is restricted to upload. </p>

<p>my current code below: </p>

<p><strong>function</strong></p>

<pre><code>function GetExtension($imagetype){
 if(empty($imagetype)) return false;
 switch($imagetype){
   case 'image/bmp': return '.bmp';
   case 'image/gif': return '.gif';
   case 'image/jpeg': return '.jpg';
   case 'image/png': return '.png';
 default: return false;
 }
}
</code></pre>

<p>code process </p>

<pre><code>if(isset($_POST['submit'])){

    $tmp_file = $_FILES['file_upload']['tmp_name'];
    $target_file = basename($_FILES['file_upload']['name']);
    $imgtype = $_FILES['file_upload']['type'];
    $ext = GetImageExtension($imgtype);
    $imagename = date("d-m-Y")."-".time().$ext;
    $upload_dir = "../images/file/".$imagename;

    if(move_uploaded_file($tmp_file, $upload_dir)){

        //// some code here...........

    } else {
        $error = $_FILES['file_upload']['error'];
    }
}
</code></pre>