使用php邮件程序无法正常工作的文件附件验证。
if(is_array($_FILES) && $_FILES['attachmentFile']['type'] == "application/pdf" && $_FILES['attachmentFile']['type'] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" && $_FILES['attachmentFile']['size'] < 2097152)
{
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
else
{
echo "<p class='error'>Cannot upload other than PDF & DocX files > 2Mb.</p>";
exit;
}
答案 0 :(得分:0)
更改 if 条件:
if(is_array($_FILES)
&& $_FILES['attachmentFile']['size'] < 2097152
&& ($_FILES['attachmentFile']['type'] == "application/pdf"
|| $_FILES['attachmentFile']['type'] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") )
{
$mail->AddAttachment($_FILES['attachmentFile']['tmp_name'],$_FILES['attachmentFile']['name']);
}
else
{
echo "<p class='error'>Cannot upload other than PDF & DocX files > 2Mb.</p>";
exit;
}