<form method="post" enctype="multipart/form-data">
<input type="file" name="images[]">
<input type="submit" name="submit_photo" value="SAVE">
</form>
当我选择文件并再次尝试选择文件$_FILES
保留最新版本时,如何合并这些版本?
答案 0 :(得分:1)
哦......好吧,即使文件控件具有多个属性,文件控件的行为如何,任何后面的文件选择都将完全取代以前的选择。所以最好的选择是使用多个文件对话框。下面是一个建议,其中我们动态创建新的文件控件
<form method="post" enctype="multipart/form-data" id="myfrm">
<input type="file" name="images[0]">
<input type="submit" name="submit_photo" value="SAVE" id="submit">
</form>
<script>
var counter = 0;
$('#yourmodal').on('show.bs.modal', function(){
counter++;
$('#myfrm').find('input[type=file]').hide(); //hide all existing file controls
var a = '<input type="file" multiple name="resume[' + counter + ']">'; // create dynamic file control
$('#submit').before(a); //append this to form
});
</script>
提交你的$ _FILES数组就是这样的。名称,文件类型将按键分组在一起
Array
(
[resume] => Array
(
[name] => Array
(
[1] => Chrysanthemum.jpg
[2] => Hydrangeas.jpg
)
[type] => Array
(
[1] => image/jpeg
[2] => image/jpeg
)
[tmp_name] => Array
(
[1] => C:\amp\tmp\phpF462.tmp
[2] => C:\amp\tmp\phpF492.tmp
)
[error] => Array
(
[1] => 0
[2] => 0
)
[size] => Array
(
[1] => 879394
[2] => 595284
)
)
)