0

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

1 回答 1

0

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

例子:

if(getimagesize($fullpath_to_file)){
 //then do something here
}
于 2013-03-28T08:18:43.203 回答