I run my php code to upload multiple file but until right now i get error like this : PHP erorr Undefined index: link_to_doc_file_
And here is my controller :
function insert_data(){
$this->form_validation->set_rules('tool_code', 'Tool Code', 'required');
if ($this->form_validation->run()){
for($i=1;$i<=10;$i++) {
$link_to_doc_file_[$i] = (isset($_GET['link_to_doc_file_'][$i]) ? $_GET['link_to_doc_file_'][$i] : null);
$link_to_doc_file_[$i] = "";
$file_uploaded = false;
//UPLOAD DOC
if(is_uploaded_file($_FILES['link_to_doc_file_']['tmp_name'][$i])){
$folder = /*base_url() .*/ 'material/';
$ext = substr($_FILES['link_to_doc_file_']['name'][$i],strpos($_FILES['link_to_doc_file']['name'][$i],'.'));
$file_name = $this->input->post('tool_code') . (int)microtime(true) . $ext;
$target_file = $folder .$file_name;
if(!file_exists($folder))
mkdir($folder);
//if(file_exists($target_file)) unlink($target_file);
if(move_uploaded_file($_FILES['link_to_doc_file_']["tmp_name"][$i], $target_file)){
$file_uploaded = true;
$$link_to_doc_file_[$i] = $target_file;
}
}
}
$tool_code = $this->input->post($tool_code);
$data_doc = null;
//Data Description
for($i=1;$i<=10;$i++){
$data_doc['title'][$i-1] = $this->input->post('doc_title_' . $i);
$data_doc['link'][$i-1] = $this->input->post('link_to_doc_file_'.$i);
$data_doc['show'][$i-1] = $this->input->post('doc_display_' . $i);
}
$data['doc'] = $data_doc;
if($this->input->post('is_edit')){
//UPDATE
$this->model_tool->update_tool_document($this, $data);
}else{
//INSERT
$this->model_tool->insert_tool_document($this, $data);
}
redirect(MENU_TOOL_DOC);
}else{
}
}
}
Here my View :
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
<?php echo (($id)?"Edit":"Add") . " Document"; ?>
</div>
<div class="panel-body">
<?php echo form_open_multipart(base_url() . MENU_TOOL_DOC . '/insert_data');?>
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<input type="hidden" name="tool_code" value="<?php echo $tool_code;?>">
<label>Tool Code : <?php echo $tool_name;?></label>
<?php
for($i=1;$i<=10;$i++){
?>
<div class="form-group">
<label>Document <?php echo $i;?></label>
<div class="form-group">
<label>Show</label>
<select class="form-control" name="doc_show_<?php echo $i;?>">
<?php
for($j=0;$j<count($show);$j++){
?>
<option value="<?php echo ($j); ?>" <?php echo (isset($row))?(($doc['show'][$i-1] == $j)?"selected":""):"";?>>
<?php echo $show[$j];?>
</option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label>Title</label>
<input class="form-control" name="doc_title_<?php echo $i;?>" value="<?php echo (isset($row))?$doc['title'][$i-1]:"";?>">
</div>
<div class="form-group form-inline">
<label>File</label>
<input type="file" name="link_to_doc_file_<?php echo $i;?>" value="<?php echo (isset($row))?$doc['link'][$i-1]:"";?>">
</div>
</div>
<?php
}
?>
</div>
<div class="col-lg-12">
<input type="hidden" name="is_edit" value="<?php echo $is_edit; ?>" />
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</div>
</div>
<?php echo form_close();?>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
if only one upload i can but if many uploads file not yet until right now.