我无法上传codeigniter中的文件,我没有收到任何错误,我很困惑为什么会发生这种情况,我也想在完成此操作后上传多个附件,但不知怎的,我不是执行这些代码时出现任何错误,是否有任何明显的错误或我错过了什么?我之前没有上传任何文件,这是我的第一次尝试。我附上下面的MVC代码:
我的观点表是:
<!-- form start -->
<?php echo form_open_multipart('exits/manager_add_absconding/'.$id,array('name'=>'addostcstevent','id'=>'addostcstevent','method'=>'post','autocomplete'=>'on','class'=>'form-horizontal'))?>
<?php echo form_hidden(array('id'=>$row->id,'action'=>$action));?>
<div class="box-body">
<input type="hidden" name="todays_date" readonly id="todays_date" value="<?php echo date('m/d/y');?>" class="form-control col-md-10" <?php if($USER->permissions[0] != 'all') { ?> readonly <?php } ?>>
<table>
<tr>
<td>
Name
</td>
<td>
<select class="form-control" name="name">
<?php
foreach($groups as $row)
{
echo '<option value="'.$row->firstname.'">'.$row->firstname.' '.$row->lastname.'</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td>
Exit Type
</td>
<td>
<select class="form-control" id="security_question_1" name="exit_type">
<option name="exit_type" value="" selected>Select a option</option>
<option name="exit_type" value="Absconding">Absconding</option>
</select>
</td>
</tr>
<tr></tr>
<tr>
<td>
<label>Absconding Since</label>
</td>
<td>
<div class="date" data-date="12-02-2012" data-date-format="mm-dd-yyyy" data-date-viewmode="years">
<input placeholder="Absconding Since" class=" m-wrap col-md-8 form-control " id="enddt" type="text" name="abscondingsince" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</td>
</tr>
<tr>
<td>
<label>Date of contact via Phone</label>
</td>
<td>
<div class="date" data-date="12-02-2012" data-date-format="mm-dd-yyyy" data-date-viewmode="years">
<input placeholder="Date of contact via Phone" class=" m-wrap col-md-8 form-control " id="enddtt" type="text" name="dateofcontactviaphone" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</td>
</tr>
<td>
<label>
Response/Outcome from attempt to contact through phone
</label>
</td>
<td>
<textarea class="form-control" name="commentsphone"></textarea>
</td>
<tr>
<td>
<label>Date of contact via email</label>
</td>
<td>
<div class="date" data-date="12-02-2012" data-date-format="mm-dd-yyyy" data-date-viewmode="years">
<input placeholder="Date of contact via email" class=" m-wrap col-md-8 form-control " id="enddttt" type="text" name="dateofcontactviaemail" value="<?php if($row->requested_date!='') echo date("d-m-Y",$row->requested_date); ?>" required/>
</td>
</tr>
<td>
<label>
Response/Outcome from attempt to contact through email
</label>
</td>
<td>
<textarea class="form-control" name="commentsemail"></textarea>
</td>
<tr>
<label>Image : </label>
<input type="file" multiple="" name="images[]">
</tr>
</tr>
</table>
</div><!-- /.box-body -->
<div class="box-footer">
<?php
echo form_hidden('action',$action);
echo form_hidden('id',$id);
?>
<!--<button type="submit" class="btn btn-info pull-right" name="withdraw" style="margin:0px 10px" value="withdrawn">Withdraw Resignation</button>-->
<button type="submit" class="btn btn-info pull-right" value="upload" style="margin:0px 10px">Submit</button>
</div><!-- /.box-footer -->
</form>
我的控制器方法是:
private function upload_files($path, $title, $files)
{
$config = array(
'upload_path' => './uploads/',
'allowed_types' => 'jpg|gif|png',
'overwrite' => 1,
);
$this->load->library('upload', $config);
$images = array();
foreach ($files['name'] as $key => $image) {
$_FILES['images[]']['name']= $files['name'][$key];
$_FILES['images[]']['type']= $files['type'][$key];
$_FILES['images[]']['tmp_name']= $files['tmp_name'][$key];
$_FILES['images[]']['error']= $files['error'][$key];
$_FILES['images[]']['size']= $files['size'][$key];
$fileName = $title .'_'. $image;
$images[] = $fileName;
$config['file_name'] = $fileName;
$this->upload->initialize($config);
if ($this->upload->do_upload('images[]')) {
$this->upload->data();
} else {
return false;
}
}
return $images;
}
function manager_add_absconding(){
global $SITE,$USER;
$data = array();
$data['row'] = new stdClass();
$data['row'] = $this->admin_init_elements->set_post_vals($this->input->post());
$data['offices']=$this->mod_common->get_all_offices();
$clients = currentuserclients();
$data['roles'] = $this->mod_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
$data['reasons'] = $this->exit_common->get_all_reasons();
$id = $this->uri->segment(3);
//$data['roles'] = $this->exit_common->get_cat_array('designation','status',"1' AND id > '0",'designation');
get_city_state_country_array($data,array('cityid'=>$data['row']->cityid));
$data['error_message'] = '';
$data['row']->id = $this->uri->segment(3);
$data['id'] = $this->uri->segment(3);
$data['action'] = 'add';
$data['heading'] = 'Add';
$data['msg_class'] = 'sukses';
$data['path']=$path;
$post_action = $this->input->post('action');
if($post_action=='add' || $post_action =='update' ){
$post_array = $this->input->post();
$action = ($post_action == 'add')?'inserted':'updated';
//echo '<pre>';print_r($SITE);die;
$post_array['exit_type'] = 'Employee Initiated';
$data['managerid'] = $this->exit_common->get_managerids($id);
$data['error_message'] = $this->exit_common->add_new_absconding_alert($post_array,$action);
if($data['error_message'] == 'Record '.$action.' successfully'){
$data['row'] = new stdClass();
$data['row']->id = $this->uri->segment(3);
$data['row']->status = 1;
}
}
$data['grievance_types'] = $this->mod_common->get_user_allowed_leaves();
if($data['row']->id>0){
$data['action'] = 'update';
$data['heading'] = 'Edit';
$data['rows'] = $this->mod_common->get_leave_request($data['row']->id);
$clid = $data['row']->id;
$data['row']->id = $clid;
}
//$data['my_detail'] = $this->mod_common->get_my_details($USER->id);
$data['my_detail'] = $this->exit_common->get_details_profile($USER->id,'users_details','userid');
$data['my_detail']->userdetail = $this->exit_common->get_details($USER->id,'users');
get_address($data['my_detail'],ADDRESS_TYPE1,$USER->id);
$data['cities']=$this->exit_common->get_array_frontend('city');
$data['notice_period']=$this->exit_common->get_notice_period($USER);
if (!empty($_FILES['images']['name'][0])) {
if ($this->upload_files($title, $_FILES['images']) === FALSE) {
$data['error'] = $this->upload->display_errors('<div class="alert alert-danger">', '</div>');
}
}
$data['groups'] = $this->exit_common->get_all_names_by_user($USER);
$this->data['maincontent'] = $this->load->view('maincontents/manager_add_new_exit', $data,true);
$this->load->view('layout', $this->data);
}