使用exif_imagetype验证图像,但仍能上载非图像文件

时间:2013-03-28 07:44:27

标签: php phpmailer exif

我不确定我的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();     
   }}

1 个答案:

答案 0 :(得分:0)

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

示例:

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