更新:我几乎解决了这个问题,请参阅Jquery 表单没有提交到 IE7 和 IE8我只需要对 ie7 和 ie8 进行排序,
我一直在使用THIS插件将文件作为电子邮件附件上传,我已经将它带到了它实际工作的地步,唯一的问题是它目前使用它来提交:
jQuery.ajax({
beforeSend: function() {
status.empty();
var percentVal = '0%';
bar.css("width", percentVal)
percent.html(percentVal);
},
uploadProgress: function(event, position, total, percentComplete) {
var percentVal = percentComplete + '%';
bar.css("width", percentVal)
percent.html(percentVal);
//console.log(percentVal, position, total);
},
complete: function(xhr) {
status.html(xhr.responseText);
}
});
我需要将其添加到的表单使用它来提交:
jQuery.ajax({
type: "POST",
url: "mail.php",
dataType: "json",
data: {parameters: jsonData}
});
我如何使插件与我的提交形式一起使用?
这是当前工作上传表单的JSFIDDLE。
然后是我需要将工作表单与JSFIDDLE结合起来的表单(我已将其缩短为仅上传字段,但还有很多其他信息)
还有这里的 php 发送函数:
<?php
function printMember($member) {
foreach($member as $key=>$value) {
//Fill the aux string first
$str.= "$key : $value <br />";
}
//string that will be added to $msg variable inside the loop
return $str;
}
$json = $_POST['parameters'];
$json_string = stripslashes($json);
$data = json_decode($json_string, true);
$depCount = count($data["dependants"]);
$msg .= "<h2>Main member data:</h2>";
$msg .= printMember($data["mainmember"]);
$msg .= "<h2>There are $depCount Dependants</h2>";
foreach ($data["dependants"] as $index => $dependant) {
$msg .= "<h2>Dependant $index</h2>";
$msg .= printMember($dependant);
}
$strTo = "dawid@jamfactory.co.za";
$strSubject = "Image Testing";
$strMessage = nl2br($msg);
//*** Uniqid Session ***//
$strSid = md5(uniqid(time()));
$strHeader = "";
$strHeader .= "From: Dawid<test@testme.co.za>\nReply-To:test@testme.co.za";
$strHeader .= "MIME-Version: 1.0\n";
$strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
$strHeader .= "This is a multi-part message in MIME format.\n";
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-type: text/html; charset=utf-8\n";
$strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
$strHeader .= $strMessage."\n\n";
//*** Attachment ***//
$count = 0;
foreach($_FILES['myfile']['name'] as $filename)
{
$temp = $_FILES['myfile']['tmp_name'][$count];
$strFilesName = $filename;
$strContent = chunk_split(base64_encode(file_get_contents($temp)));
$strHeader .= "--".$strSid."\n";
$strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";
$strHeader .= "Content-Transfer-Encoding: base64\n";
$strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
$strHeader .= $strContent."\n\n";
$count++;
}
$flgSend = @mail($strTo,$strSubject,null,$strHeader); // @ = No Show Error //
if($flgSend)
{
echo "Mail send completed.";
}
else
{
echo "Cannot send mail.";
}
?>
如果有人不完全理解这个问题,我会在这里尝试进一步解释:
我有可重复的字段,在提交时将信息放入 JSON 数组,然后通过 PHP 解析为电子邮件,我想做的是有一个文件字段,其中图像被上传并与电子邮件一起发送,但之后在网上进行了很多研究,我发现这对于 ajax 是不可能的,所以我发现这个插件实际上可以工作,现在我只是想把它和我原来的形式结合起来