On my upload form I have multiple links and userfiles. I would like to be able to insert the link/url where matches up with the image that is on that table row, so far what I have tried has not worked. I have made the link and userfile into array the images upload fine.
In my controller you will be able to see what I have tested for model.
What I would like to know what is best to make it so when the user selects the image when insert into data base that the input of the url/link input will match the image file name
Thank in advance. If you decided to vote down can you let me know why cheers!
Banner Form
<?php echo Modules::run('admin/common/header/index');?><?php echo Modules::run('admin/common/column_left/index');?>
<div id="content">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading clearfix">
<div class="pull-right">
</div>
</div>
<div class="panel-body">
<?php echo $error;?>
<?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[]" placeholder="url"></td>
<td><input type="file" name="userfile[]" size="20" multiple="multiple" /></td>
</tr>
<tr>
<td><input type="text" name="link[]" placeholder="url"></td>
<td><input type="file" name="userfile[]" size="20" multiple="multiple" /></td>
</tr>
</tbody>
</table>
<input type="submit" value="upload" />
</form>
</div>
</div>
</div>
</div>
</div>
</div>
Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Banners extends MX_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$data['error'] = '';
$this->load->view('design/banner_form.tpl', $data);
}
public 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() == FALSE) {
$data['error'] = $this->upload->display_errors();
$this->load->view('design/banner_form.tpl', $data);
} else {
/*
|
| Model Function Here For Tesing Only
| Will make proper model function when issue sorted.
|
*/
$upload_infos = $this->upload->data();
foreach ($upload_infos as $upload_info) {
$data = array(
'image' => $upload_info['file_name'],
//'link' => $this->input->post('link')
);
}
$this->db->insert('banner_image', $data);
return $this->load->view('design/banner_list.tpl', $data);
}
}
}
private function file_config() {
$config = array();
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '3000';
$config['overwrite'] = TRUE;
return $config;
}
}