使用exif_imagetype验证图像,但仍然可以上传非图像文件


Validate Image with exif_imagetype but still able to upload non image files

我不确定我的exif_imagetype是否编码错误。它发送的电子邮件附上了照片。但是当我尝试附加非图像文件时,它仍然允许我这样做并发送带有附件的电子邮件。请帮助。

    ob_start();
require("class.phpmailer.php");
    $photo = $_FILES['photo'];
    isset($_POST['submit']);
$active_keys = array();
foreach($_FILES[$photo]['name'] as $key => $filename){
if(!empty($filename)){
    $active_keys[] = $key;
}    }
foreach($active_keys as $key){    
switch(exif_imagetype($_FILES[$photo]['tmp_name'][$key])) {
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
    break;
    default:
 echo "{";
 echo        "$errors: 'This is no photo..''n";
 echo "}";
  exit(0);
    } }
$message = "some message";
$mail = new PHPMailer();
$mail->From     = ('sample@youdomain.net');
$mail->AddAddress=('sample@youdomain.net');
$mail->Subject  = "Submitted Photos";
$mail->Body     = $message;
$mail->WordWrap = 50;
foreach($_FILES['photo']['tmp_name'] as $photo) 
if(!empty($photo)) {
     $mail->AddAttachment($photo);
}
$mail->Send();

header("Location: thankyou.php");
   exit();     
   }}

在处理任何东西之前使用getimagesize()函数,它提供更好的结果

的例子:

if(getimagesize($fullpath_to_file)){
 //then do something here
}