dqef7931 2016-12-15 11:00
浏览 53

jQuery文件上传为电子邮件附件

I want to know how to send email attachments using jquery file uploads

from this plugin https://blueimp.github.io/jQuery-File-Upload/

is there a way to do that. or i have to use regular input files

here is my script for sending email

<?php
if(isset($_FILES) && (bool) $_FILES) {
    $AllowedExtensions = ["pdf","doc","docx","gif","jpeg","jpg","png","rtf","txt"];
    $files = [];
    $server_file = [];
    foreach($_FILES as $name => $file) {
        $file_name = $file["name"];
        $file_temp = $file["tmp_name"];
        foreach($file_name as $key) {
            $path_parts = pathinfo($key);
            $extension = strtolower($path_parts["extension"]);
            if(!in_array($extension, $AllowedExtensions)) { die("Extension not allowed"); }
            $server_file[] = "uploads/{$path_parts["basename"]}";
        }
        for($i = 0; $i<count($file_temp); $i++) { move_uploaded_file($file_temp[$i], $server_file[$i]); }
    }
    $to = "admin@itc-4u.net";
    $from = "o0medo90o@gmail.com";
    $subject ="test attachment";
    $message = "this is a test message";
    $headers = "From: $from";
    $semi_rand = md5(time());
    $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
    $headers .= "
MIME-Version: 1.0
" . "Content-Type: multipart/mixed;
" . " boundary=\"{$mime_boundary}\"";
    $message = "This is a multi-part message in MIME format.

" . "--{$mime_boundary}
" . "Content-Type: text/plain; charset=\"iso-8859-1\"
" . "Content-Transfer-Encoding: 7bit

" . $message . "

";
    $message .= "--{$mime_boundary}
";
    $FfilenameCount = 0;
    for($i = 0; $i<count($server_file); $i++) {
        $afile = fopen($server_file[$i],"rb");
        $data = fread($afile,filesize($server_file[$i]));
        fclose($afile);
        $data = chunk_split(base64_encode($data));
        $name = $file_name[$i];
        $message .= "Content-Type: {\"application/octet-stream\"};
" . " name=\"$name\"
" .
            "Content-Disposition: attachment;
" . " filename=\"$name\"
" .
            "Content-Transfer-Encoding: base64

" . $data . "

";
        $message .= "--{$mime_boundary}
";
    }
    if(mail($to, $subject, $message, $headers)) {
        echo "<p>mail sent to $to!</p>";
    } else {
        echo "<p>mail could not be sent!</p>";
    }
}

?>

and this is the html for the plugin i want to modify

    <form id="fileupload" method="POST" enctype="multipart/form-data">
    <!-- Redirect browsers with JavaScript disabled to the origin page -->
    <noscript><input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/"></noscript>
    <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
    <div class="row fileupload-buttonbar">
        <div class="col-lg-7">
            <!-- The fileinput-button span is used to style the file input field as button -->
            <span class="btn btn-success fileinput-button">
                <i class="glyphicon glyphicon-plus"></i>
                <span>Add files...</span>
                <input type="file" name="files[]" multiple>
            </span>
            <button type="submit" class="btn btn-primary start">
                <i class="glyphicon glyphicon-upload"></i>
                <span>Start upload</span>
            </button>
            <button type="reset" class="btn btn-warning cancel">
                <i class="glyphicon glyphicon-ban-circle"></i>
                <span>Cancel upload</span>
            </button>
            <button type="button" class="btn btn-danger delete">
                <i class="glyphicon glyphicon-trash"></i>
                <span>Delete</span>
            </button>
            <input type="checkbox" class="toggle">
            <!-- The global file processing state -->
            <span class="fileupload-process"></span>
        </div>
        <!-- The global progress state -->
        <div class="col-lg-5 fileupload-progress fade">
            <!-- The global progress bar -->
            <div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100">
                <div class="progress-bar progress-bar-success" style="width:0%;"></div>
            </div>
            <!-- The extended global progress state -->
            <div class="progress-extended">&nbsp;</div>
        </div>
    </div>
    <!-- The table listing the files available for upload/download -->
    <table role="presentation" class="table table-striped"><tbody class="files"></tbody></table>

    <input type="submit" value="Submit" />
</form>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集