我有一个像这样在我的HTML表单一个共同的输入和两个文件输入多张:
div class="col-md-4">
<div class="form-group">
<label class="control-label col-md-3">Size</label>
<div class="col-md-9">
<?php
$size = array(
"type" => "text",
"name" => "size",
"id" => "size",
"class" => "form-control"
);
echo form_input($size);
?>
<span class="help-block"></span>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-2">Image Container:</label>
<div class="col-md-10">
<input type="file" multiple="" name="images_container[]" id="file_container" required="required">
<p class="help-block"></p>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label class="control-label col-md-2">Image If Coil Is Damage</label>
<div class="col-md-10">
<input type="file" multiple="" name="images[]" id="files" >
<p class="help-block"></p>
</div>
</div>
</div>
我抢他们用ajax jquery的
$('#form').submit(function() {
$('#btnSave').text('saving...'); //change button text
$('#btnSave').attr('disabled', true); //set button disable
var url;
var fd = new FormData();
var file_data = $('#files')[0].files; // for multiple files
var file_data_container = $('#file_container')[0].files; // for multiple files
for (var j = 0; j < file_data_container.length; j++) {
fd.append("file_container_" + j, file_data_container[j]);
}
for (var i = 0; i < file_data.length; i++) {
fd.append("file_coil" + i, file_data[i]);
}
var other_data = $(this).serializeArray();
$.each(other_data, function (key, input) {
fd.append(input.name, input.value);
});
$.ajax({
url: url,
type: "POST",
data: fd,
processData: false,
contentType: false,
dataType: "JSON",
success: function (data){}
});
所以,$从阿贾克斯提交_FILES数组是这样的:
Array
(
[file_container_0] => Array
(
[name] => bonus.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php95B4.tmp
[error] => 0
[size] => 616252
)
[file_container_1] => Array
(
[name] => coolas.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9613.tmp
[error] => 0
[size] => 641576
)
[file_container_2] => Array
(
[name] => preview.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9633.tmp
[error] => 0
[size] => 474285
)
[file_coil0] => Array
(
[name] => 1280x800.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9653.tmp
[error] => 0
[size] => 214172
)
[file_coil1] => Array
(
[name] => 1280x960.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9674.tmp
[error] => 0
[size] => 261002
)
)
我的问题是,我怎么可以拆分该数组这个数组分成两个数组。
第一个数组
Array
(
[file_container_0] => Array
(
[name] => bonus.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php95B4.tmp
[error] => 0
[size] => 616252
)
[file_container_1] => Array
(
[name] => coolas.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9613.tmp
[error] => 0
[size] => 641576
)
[file_container_2] => Array
(
[name] => preview.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9633.tmp
[error] => 0
[size] => 474285
)
)
第二个数组
Array
(
[file_coil0] => Array
(
[name] => 1280x800.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9653.tmp
[error] => 0
[size] => 214172
)
[file_coil1] => Array
(
[name] => 1280x960.jpg
[type] => image/jpeg
[tmp_name] => D:\xampp\tmp\php9674.tmp
[error] => 0
[size] => 261002
)
)
你能解释一下你的真正目标是什么?你想通过数组重命名来实现什么? – fusion3k
每个文件输入都存储在表中。将容器插入tb_container,并将其卷入tb_coil –