我已经包含了一个代码在我的php形式附加文件,请找到下面的代码。在我的代码中,我提到只接受*.doc, *.docx和*.pdf,但它接受所有扩展名
function checkType() {
if(!empty($_FILES['fileatt']['type'])){
if(($_FILES['fileatt']['type'] != "application/msword")||($_FILES['fileatt']['type'] != "application/vnd.openxmlformats-officedocument.wordprocessingml.document")||($_FILES['fileatt']['type'] != "application/pdf")) {
echo "Sorry, current format is <b> (".$_FILES['fileatt']['type'].")</b>, only *.doc, *.docx and *.pdf are allowed." ;
}
}
}
function checkType() {
if(!empty($_FILES['fileatt']['type'])){
$allowed = array('doc','docx' ,'pdf');
$filename = $_FILES['fileatt']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!in_array($ext,$allowed) ) {
echo "Sorry, current format is <b> (".$_FILES['fileatt']['type'].")</b>, only *.doc, *.docx and *.pdf are allowed." ;
return false;
}
}
return true;
}
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
你可以使用下面的命令将图像转换为word格式。或者您可以将扩展存储在数组中,并可以检查有效编码的条件。我只是给你一个想法不是确切的答案
您可以使用in_array()检查扩展
function checkType($data, $ext)
{
$filename = $data['name'];
$pathinfo = pathinfo($filename, PATHINFO_EXTENSION);
// Checking
if(in_array($pathinfo, $ext))
{
// TRUE
return TRUE;
}
// FALSE
return FALSE;
}
$checkType = checkType($_FILES['video_file'], array('doc', 'docx', 'pdf');
var_dump($checkType);