我创建了一个动态表。用户可以添加和删除行。在每一行中都有用于上传文件的列。
<tr><td><label><input type='file' class='upload_act' /></td></tr>
我使用function
将name
添加到文件上传中,因为表格行可能会频繁更改。
function reCalculate(){
$("#t_object tbody .tr_content").each(function(i){
$(this).find('td:eq(0)').text(i+1);
$(this).find("input[class^='date_uploaded']").attr('name',"detail["+i+"][dt_upl]");
$(this).find("input[class^='upload_act']").attr('name',"detail["+i+"][upload_act]");
});
}
这是我处理提交的文件:
public function save_activity_m(){
$details = $this->input->post('detail');
$i = 0;
foreach($details as $rows){
//UPLOAD RULES
$upload_name = "detail[".$i."][upload_act]";
$config['upload_path'] = FCPATH."assets/uploads/memo/";
$config['allowed_types'] = 'gif|jpg|jpeg|png|pdf|rar|zip|7z';
$config['max_size'] = '2048';
$config['file_name'] = $rows['dt_upl'];
$config['remove_spaces'] = TRUE;
$config['overwrite'] = TRUE;
$this->load->library('upload', $config);
$this->upload->initialize($config);
if(!$this->upload->do_upload($upload_name)){
echo "<script type='application/javascript'>";
echo "alert('Oops something wrong. Please contact the admin');window.top.location.reload();";
echo "</script>";
}
else{
$i += 1;
echo "<script type='text/javascript'>alert('Congratulaions. Your data is succesfully saved');window.top.location.reload();</script>";
}
}
//echo json_encode($details);
}
我认为问题出在$upload_name
。但是,我不知道什么是错的。我需要一些启发。
注意:
忽略IF
,数据已成功保存,但文件未上传