[eluser]Unknown[/eluser]
Hello guys,
I have a problem to climb multiple files.
I researched and found a few ways to climb several files.
Occurs that need rescuing file names to insert them in certain fields in a table.
If anyone can to help, thank you.
hugs
My Table Services
id int(10)
desc varchar(30)
espec text
img00 varchar(45)
img01 varchar(45)
img02 varchar(45)
img03 varchar(45)
Code:
// My view
echo form_open_multipart(base_url().'admin/services/add');
echo form_fieldset("Test");
echo '<table class="table">';
echo '<tbody>';
echo '<tr>';
echo '<td>';
//Titulo
echo form_label('Title');
echo '<input type="text" name="desc">';
echo '</td>';
echo '<td>';
echo form_label('Principal Image', 'userfile');
echo form_upload('userfile');
echo '</tr>';
echo '</tbody>';
echo '</table>';
//Especif
echo '<table class="table">';
echo '<tbody><tr>';
echo '<td>';
echo form_label('Espec');
echo '<textarea name="espec">';
echo '</textarea>';
echo '</td>';
echo '<td>';
echo form_label('Image 01', 'img01');
echo form_upload('img01');
echo form_label('Image 02', 'img02');
echo form_upload('img02');
echo form_label('Image 03', 'img03');
echo form_upload('img03');
echo '</td>';
echo '</tr></tbody></table>';
echo form_submit('mysubmit','Add');
echo form_reset('myreset','Cancel');
echo form_fieldset_close();
echo form_close();
Code:
// My Controler Sevices
function add(){
$this->load->library('form_validation');
$config = array(
array('field' =>'desc','label' =>'Title','rules' =>'required'),
array('field' =>'espec','label' =>'Espec','rules' =>'required')
);
$this->form_validation->set_rules($config);
if ($this->form_validation->run() == FALSE){
$this->index();
}
else {
$config['upload_path'] = 'assets/img/services';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 0;
$config['max_width'] = 600;
$config['max_height'] = 400;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if(!$this->upload->do_upload()){
echo $this->upload->display_errors();
}
else {
$image0 = $this->upload->data();
$dados['img00'] = $image0['file_name'];
$image1 = $this->upload->data();
$dados['img01'] = $image1['file_name'];
$image2 = $this->upload->data();
$dados['img02'] = $image2['file_name'];
$image3 = $this->upload->data();
$dados['img03'] = $image3['file_name'];
$dados['desc'] = $this->input->post('desc');
$dados['espec'] = $this->input->post('espec');
$this->load->model('admin/services_model');
if ($this->services_model->add($dados)){
redirect(base_url().'admin/services/', 'refresh');
}
else {
echo 'Error';
}
}
}
}
Code:
// My Model
class Services_model extends CI_Controller{
function __construct() {
parent::__construct();
}
function add($dados){
return $this->db->insert('services',$dados);
}