我正在写一个上传文件页面。这是html代码:
<form action="verify.php" id="upload" method="post" enctype="multipart/form-data">
<input id="file_upload" type="file" name="file_upload" />
<button id="submit" name="submit" type="submit">Upload</button>
</form>
这是我的PHP代码:
if ($_FILES['file_upload']['error']==UPLOAD_ERR_NO_FILE){
return;
}
try{
$email_add='MY@gmail.com';
$subject="Driver Verification";
$mail = $this->emailConfig();
$mail->addAddress($email_add, "LALALA"); // Add a recipient
$mail->Subject = $subject;
echo $_FILES['file_upload']['name'];
echo $_FILES['file_upload']['tmp_name'];
$mail->Body = "This driver requires a verification."
$mail->AddAttachment($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
return;
}
catch(PDOException $e){
return;
}
}
因此,当我运行代码时,它只能回显[&#39; name&#39;]但不能回显[&#39; tmp_name&#39;],因此没有电子邮件附件。
有什么想法?感谢。