使用ajax进度条时不附加文件

时间:2013-09-05 10:15:57

标签: php jquery ajax

我正在使用Mail附件。我可以使用普通MAIL CLASS发送邮件和附件,但是当我将此AJAX FILE UPLOAD与邮件类一起使用时,我正在获取附件,但不是我上传到服务器的文件。例如。 Test.doc的。在我收到的电子邮件中,我收到了通过我的联系表单发送的电子邮件和附件,但没有附上正确的文件。而不是Test.doc我收到的是一个没有任何扩展名的简单“上传”文件。

Controller.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

    <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 /上传。我可以看到上传到uploads文件夹的文件。例如。 Test.doc,test.docx。 test.zip等。

这就是我得到的

enter image description here

1 个答案:

答案 0 :(得分:0)

我的猜测是$_FILES['upl']['name']中的$mail->addAttachment('./uploads/'.$_FILES['upl']['name']);不再存在了。尝试通过变量传递文件名。

$fname = './uploads/'.$_FILES['upl']['name'];
if(move_uploaded_file($_FILES['upl']['tmp_name'], $fname)){
    echo '{"status":"success", "fname" : "'.$fname.'"}';
    exit;
}