0

我正在使用以下脚本来验证上传的文件是否为 pdf 以及是否使用 phpmailer 发送。它发送电子邮件,但没有附件。此外,它还允许我附加非 pdf 文件。请帮忙。

ob_start();
require("class.phpmailer.php");

if(isset($_FILES['upload']['tmp_name'])){
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime=finfo_file($finfo, $_FILES['upload']['tmp_name']);
if($mime=='application/pdf'){

$message = "some message";
$mail = new PHPMailer();
$mail->From     = ('sample@youdomain.net');
$mail->AddAddress=('sample@youdomain.net');
$mail->Subject  = "Submitted files";
$mail->Body     = $message;
$mail->WordWrap = 50;

foreach($_FILES['upload']['tmp_name'] as $upload) 
if(!empty($upload)) {
$mail->AddAttachment($upload);
}
$mail->Send();

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

1 回答 1

0

目前您有:

if( ... ) { 
    ...
    if($mime=='application/pdf') {
    }
}
// some code you want to be executed
// only if the mime type is application/pdf

但你想要:

if (...) {
  ..
  if ($mime=='application/pdf') {
        // place the code you want to be executed
        // only if the mime type is application/pdf
        // here - before the closing }
    }
}
于 2013-03-28T08:21:55.280 回答