I am trying to set restriction on uploading files to php server but thats not working except only txt file.
here is code.
$allowedExts = array("text", "doc","rtf");
$temp = explode(".", $_FILES["datafile"]["name"]);
$extension = end($temp);
if (isset($_FILES['datafile']['tmp_name'])) {
if (($_FILES['datafile']['type'] == "text/plain") || ($_FILES['datafile']['type'] == "application/msword") || ($_FILES['datafile']['type'] == "application/rtf") && in_array($extension, $allowedExts)) {
$lines = file($_FILES['datafile']['tmp_name'],FILE_IGNORE_NEW_LINES);
$data = json_encode($lines);
if (!empty($_FILES['datafile']['tmp_name'])) {
$File = "<b>Selected File:</b> ".$_FILES['datafile']['name'];
}else{
$File = "No file selected";
};
} else {
if (empty($_FILES['datafile']['tmp_name'])){
$File = "<b>Selected File:</b> No file selected";
}else {
$File = "<b>Invalid File</b>";
}
}
}
So where is problem? when I choose other files .doc or .rtf the error occured $File = "<b>Invalid File</b>";
.
any help would be appreciatd. thankx