//take the file name, and then get all the stuff after the last '.' (the file extension) $file_name = $_FILES['img1']['name']; $file_name = strrchr($file_name, "."); //make sure file type is supported $ext = array(".pdf", ".doc", ".xls", ".ppt"); if(!in_array($file_name,$ext)) { $error = "File type not supported. Supported files are "; foreach( $ext as $exts ){ $error .= "$exts "; } die ("$error"); }