通过Jquery向PHP发送多个上传
我知道在这个问题上有几个问题,我已经梳理了其中的许多问题,但没有找到一个正确的方法来正确地实现目标。本质上,我试图捕获表单中的多个文件输入,并将它们推送到PHP。我至少了解了PHP部分,但我正在努力解决的是Jquery。通过调试我注意到的一个主要问题是我的动作参数根本无法通过。我发布的代码如下。任何帮助都将不胜感激。谢谢通过Jquery向PHP发送多个上传,php,jquery,ajax,Php,Jquery,Ajax,我知道在这个问题上有几个问题,我已经梳理了其中的许多问题,但没有找到一个正确的方法来正确地实现目标。本质上,我试图捕获表单中的多个文件输入,并将它们推送到PHP。我至少了解了PHP部分,但我正在努力解决的是Jquery。通过调试我注意到的一个主要问题是我的动作参数根本无法通过。我发布的代码如下。任何帮助都将不胜感激。谢谢 $(document).ready(function () { //if submitting imgages form $('#submit').click(func
$(document).ready(function () {
//if submitting imgages form
$('#submit').click(function () {
// match anything not a [ or ]
regexp = /^[^[\]]+/;
var fileInput = $('.putImages input[type="file"]');
var fileInputName = regexp.exec(fileInput.attr('name'));
// make files available
var data2 = new FormData(fileInput);
jQuery.each($(fileInput)[0].files, function (i, file) {
data2.append(fileInputName + '[' + i + ']', file);
});
//organize data
var data = new FormData($('input[name^="uploadFile"]'));
jQuery.each($('input[name^="uploadFile"]')[0].files, function (i, file) {
data.append(i, file);
});
$.ajax({
type: 'GET',
url: 'productadminupdate.php',
data: data2 + "&action=" + 'images',
cache: false,
contentType: false,
processData: false,
success: function (response) {
$('#imgform_result').html(response).fadeIn();
}
});
return false;
});
});
我不知道我是否得到了它,但当人们想到ajax上传器时,他们并不知道这一点。事实上,这并不是JavaScript在起作用。 该技术存在于将表单的操作定向到Iframe中。 应该隐藏此Iframe 以下是一个例子:
<form method='post' enctype='multipart/form-data' action='YOUR_FILE.php' target='upload_iframe'>
<label>photo1:</label>
<input type='file' name='photo1'/>
<label>photo2:</label>
<input type='file' name='photo2'/>
<label>photo3:</label>
<input type='file' name='photo3'/>
<label>photo4:</label>
<input type='file' name='photo4'/>
<label>photo5:</label>
<input type='file' name='photo5'/>
<input type='submit' value='Send'/>
</form>
</div>
<iframe name='upload_iframe'></iframe>
照片1:
照片2:
照片3:
照片4:
照片5:
因此,在Iframe中,您的php代码将进行上载,使用$\u文件获取信息。实现所需的唯一方法是在用户退出时将每个
输入[name^=“uploadFile”]
包装在
中。然后我们可以有一个通用的提交函数。当他们点击它时,我们阻止默认功能。迭代所有表单元素,获取我们需要的数据,然后使用$('form').submit()执行正常功能。