On my view I am trying to get it so if my input link[] is next to the upload button then that link post will be inserted into the database with image I use codeigniter for a mvc frame work.
I can insert the links and images fine, but the link/url that I type in, in each link input are not matching the uploaded filename. How can I resolve this?
Thanks In Advance
function do_upload() {
$files = $_FILES;
$file_loop = count($_FILES['userfile']['name']);
for($i= 0; $i < $file_loop; $i++) {
$_FILES['userfile']['name'] = $files['userfile']['name'][$i];
$_FILES['userfile']['type'] = $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error'] = $files['userfile']['error'][$i];
$_FILES['userfile']['size'] = $files['userfile']['size'][$i];
$this->upload->initialize($this->file_config());
if (!$this->upload->do_upload()) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('design/banner_form.tpl', $error);
} else {
$data['link'] = $this->input->post('link');
if (isset($data['link'])) {
foreach ($data['link'] as $link) {
$data = array(
'link' => $link,
'image' => $files['userfile']['name'][$i]
);
}
}
$this->db->insert('banner_image', $data);
$this->load->view('design/banner_list.tpl', $data);
}
}
}
View
<?php echo form_open_multipart('admin/design/banners/do_upload');?>
<table>
<thead>
<tr>
<td>Link</td>
<td>Image</td>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" name="link[]" /></td>
<td><input type="file" name="userfile[]" size="20" multiple="multiple" /></td>
</tr>
<tr>
<td><input type="link" name="link[]" multiple="multiple" /></td>
<td><input type="file" name="userfile[]" size="20" multiple="multiple" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="upload" />
</form>