Also you have mentioned you would like to allow only some file types. Here is the code:
if (isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
$allowed = array('txt','doc','jpg');
$filename = $_FILES['uploaded_file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
$message = 'Attachment type not allowed!';
}
}
It needs to be placed before this line
if($message=='' && (isset($_POST['action']) && $_POST['action']=='js')){
I have already type it there and tested it, you will just need to add more extensions you would like to allow
Cheers :)