[英]check if specific file inputs are submitted with the form using PHP
I have a form with some dynamic file inputs. 我有一个带有一些动态文件输入的表单。 the name of the input files are set using a counter. 输入文件的名称使用计数器设置。
$("#addCompanionBtn").click(function(){
counter++;
var CompanionFields = '<input class="form-control" name="com_photo_'+counter+'" type="file" />';
$('#companionsDiv').after(CompanionFields);
});
I am using PHP to process the form. 我正在使用PHP处理表单。 How am i supposed to check if a file is submitted with the form or not!!? 我应该如何检查文件是否以表格形式提交?! Since the up to 10 files can be uploaded with the form, it is not a rational approach to check files as bellow: 由于最多可以通过该表格上载10个文件,因此检查文件如下不是一种合理的方法:
if(isset($_FILES['com_photo_1']) or isset($_FILES['com_photo_2'])){...}
Any idea is appreciated! 任何想法表示赞赏!
JQuery JQuery的
$("#addCompanionBtn").click(function(){
var CompanionFields = '<input class="form-control" name="com_photo[]" type="file" />';
$('#companionsDiv').after(CompanionFields);
});
PHP PHP
if(isset($_FILES['com_photo'])){
foreach($_FILES['com_photo'] as $photo){
//Do Stuff here
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.