我正在处理邮件附件。我可以使用普通的MAIL CLASS发送邮件和附件,但是当我将这个AJAX 文件上传与邮件类一起使用时,我得到的是附件,而不是我上传到服务器的文件。例如。测试.doc。在我收到的电子邮件中,我确实收到了我的联系表格发送的电子邮件和附件,但它没有附加正确的文件。而不是 Test.doc 我收到的是一个没有任何扩展名的普通“上传”文件。
控制器.php
$allowed = array('png', 'jpg', 'gif','zip', 'doc', 'docx', 'xps');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
if(move_uploaded_file($_FILES['upl']['tmp_name'], './uploads/'.$_FILES['upl']['name'])){
echo '{"status":"success"}';
exit;
}
}
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
$mail = new Mail();
$mail->protocol = $this->config->get('config_mail_protocol');
$mail->parameter = $this->config->get('config_mail_parameter');
$mail->hostname = $this->config->get('config_smtp_host');
$mail->username = $this->config->get('config_smtp_username');
$mail->password = $this->config->get('config_smtp_password');
$mail->port = $this->config->get('config_smtp_port');
$mail->timeout = $this->config->get('config_smtp_timeout');
$mail->setTo($this->config->get('config_email'));
$mail->setFrom($this->request->post['email']);
$mail->setSender($this->request->post['name']);
$mail->addAttachment('./uploads/'.$_FILES['upl']['name']);
$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
$mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
$mail->send();
$this->redirect($this->url->link('services/printing/success'));
}
$this->data['action'] = $this->url->link('services/printing');
形式
<form id="upload" action="<?php echo $action; ?>" method="post" enctype="multipart/form-data">
<div id="drop">
Drop Here
<a>Browse</a>
<input type="file" name="upl" multiple />
</div>
<ul>
<!-- The file uploads will be shown here -->
</ul>
</form>
'./uploads/ 是上传到我的服务器的文件所在的文件夹。它位于根目录中。例如public_html/上传。我可以看到上传到上传文件夹的文件。例如。测试.doc,测试.docx。test.zip 等
这就是我得到的