javascript - Multiple File Uploads As Email Attachments -
i display files before sent via email attachments. use script display files
$(function(){ var ul = $('#po_award p#file_1'); $('#po_award').fileupload({ add: function (e, data) { var tpl = $('<li class="dialog"><a style="color: #777777"></a></li>'); tpl.find('a').text(data.files[0].name) .append('<a href="javascript:void(0)"><span style="color: red; float: right">delete</span></a>'); data.context = tpl.prependto(ul); tpl.find('span').click(function(){ if(tpl.hasclass('dialog')){ jqxhr.abort(); } tpl.fadeout(function(){ tpl.remove() }); }); var jqxhr = data.submit(); }, }); });
and script index , call script above
<html> <head> <script type="text/javascript" src="script.js"></script> </head> <body> <form action="upload.php" id="form" method="post" enctype="multipart/form-data"> <div class="fitem"> <label style="width: 400px">upload files :</label> </div> <div class="fitem" style="float: left"> <input style="width: 65px; height: 75px; float: right" class="easyui-filebox" name="attachment[]" multiple="true" buttontext="add files"/> </div> <div class="easyui-panel" style="width:440px;height:75px;padding:5px;margin-top:0px"> <p id="file_1" style="list-style-type: none; margin-top: 0px"></p> </div><br> </form> <button type="submit" name="submit" form="form">send</button> </body> </html>
this upload.php script
<?php require 'mail/phpmailerautoload.php'; include "conn.php"; date_default_timezone_set("asia/jakarta"); $id = 1; $to = 'receiver@email.com'; $subject = 'test'; if(isset($_post['submit'])){ $attachment_name = $_files['attachment']['name']; $attachment_type = $_files['attachment']['type']; $attachment = $_files['attachment']['tmp_name']; include 'smtp.php'; $mail->addaddress($to); $mail->subject = $subject; $mail->msghtml('tes'); foreach($attachment_name $key => $att){ $nama_file = $attachment_name[$key]; $tmp_file = $attachment[$key]; $mail->addattachment($tmp_file, $nama_file); } if (!$mail->send()) { echo '<script>alert("failed"); </script>'; } else { echo '<script>alert("success"); </script>'; } } ?>
my problem is, when script.js included in index, files can't appear in email attachments. when script.js deleted index, files can appear in email attachments.
any solution this?
you didn't mention file upload plugin you're using, i've used handle upload of file server side callback , don't add data form itself. https://github.com/blueimp/jquery-file-upload/wiki/options#add
what have handle upload in seperate script , example return json info file.
then in success callback of submit method add data need form can submit script sends email
Comments
Post a Comment