如何防止$ _FILES丢失数据 [英] How prevent $_FILES loss data
本文介绍了如何防止$ _FILES丢失数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<form method="post" enctype="multipart/form-data">
<input type="file" name="images[]">
<input type="submit" name="submit_photo" value="SAVE">
</form>
当我选择文件并再次尝试选择文件$_FILES
保留最新版本时,如何合并这些版本?
When I choose file and after again try to choose file $_FILES
keeps last version, how can I merge these versions?
推荐答案
哦..很好,这就是文件控制的行为,即使它具有多个属性,随后选择的任何文件也将完全替换先前的选择.因此,最好的选择是使用多文件对话框.下面是我们建议动态创建新文件控件的建议
Ohh .. well that's how file control behaves even if it has multiple attribute , any following file choosing will completely replace previous selection.So the best option is to use multiple file dialog .Below is a suggestion in which we create new file controls dynamically
<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数组时将是这样,即.文件的名称,类型将在
On submitting your $_FILES array will be something like this ie. the names, types of file will be grouped together under the keys
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
)
)
)
这篇关于如何防止$ _FILES丢失数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文