大家好我通过使用jquery面对一个问题我是允许用户在检查时上传文件但是在检查时上传文件不是必要的但在我的PHP中它检查文件是否已上传如果文件未上传而不允许在数据库中保存复选框值,那么如何解决此问题并且我想保存数据库中的两个复选框值并上传哪个复选框文件?
PHP代码:
//declare variable for get value of checkbox
$j = 0;
//loop for check every input file name to check it user is uploaded file?
for($i = 0; $i <= 7; $i++){
// if size of file is higher than 0 bytes than it can upload
if($_FILES['checkboxfile'.$i]['size'] > 0){
// get checkbox value
$checkboxvalue = $checkbox[$j];
// lets upload file
if($this->upload->do_upload('checkboxfile'.$i)){
$upload_data = $this->upload->data();
// get filename
$filename = $upload_data['file_name'];
//array for saaving data in database
$checkboxinfo = array(
'UniqueID'=>$uniqueid,
'Product'=>$checkboxvalue,
'Image'=>$uniqueid.'/'.$filename
);
$this->Postingad->checkbox($checkboxinfo);
}
$j++;
}
}
HTML code:
<div class="checkbox">
<label for="email">electronics
<input type="checkbox" name="product_category[]" value="electronics" id="product_category" class="electronics">
</label>
</div>
<div class="form-group" id="efileu" style="display:none;" >
<input type="file" name="checkboxfile0" id="efile" style="width:100%">
</div>
<div class="checkbox">
<label for="email">kitchen
<input type="checkbox" name="product_category[]" value="kitchen" id="product_category" class="kitchen">
</div>
<div class="form-group" id="kfileu" style="display:none;" >
<input type="file" name="checkboxfile1" id="kfile" style="width:100%">
</div>
<div class="checkbox">
<label for="email">Decoratives / Interior
<input type="checkbox" name="product_category[]" value="decoratives / Interior" id="product_category" class="Interior">
</div>
<div class="form-group" id="dfileu" style="display:none;" >
<input type="file" name="checkboxfile2" id="dfile" style="width:100%">
</div>