1
I have a system that performs multi file upload, I am using the Codeigniter framework that extends to Class Upload
CI. The files are being moved correctly to the desired folder, however when entering the database records only one.
Controller:
if ($this->form_validation->run() == TRUE):
$upload = $this->protocolo->do_upload('arquivo');
if (is_array($upload) && $upload['file_name'] != ''):
$dados['arquivo'] = $upload['file_name'];
$this->protocolo->do_insert($dados);
endif;
View:
echo form_label('Arquivo');
echo form_upload(array('name' => 'arquivo[]', 'class' => 'arquivo', 'multiple' => ''), set_value('arquivo'));
Upload model:
public function do_upload($campo = 'arquivo') {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if ($this->upload->do_multi_upload($campo)):
return $this->upload->data();
else:
return $this->upload->display_errors();
endif;
}
Data insertion model:
public function do_insert($dados = NULL) {
if ($dados != NULL):
$this->db->insert('protocolo', $dados);
endif;
}
I performed a test, I used a function that the multi upload class offers, called get_multi_upload_data()
and she returned me the data correctly:
if ($this->form_validation->run() == TRUE):
$upload = $this->protocolo->do_upload('arquivo');
if (is_array($upload) && $upload['file_name'] != ''):
echo '<pre>';
$upload = $this->upload->get_multi_upload_data();
print_r($upload);
echo '</pre>';
Array ( [0] => Array ( [file_name] => 311cc35c96ca64b7750cdce8e8f548d1.jpg [file_type] => image/jpeg [file_path] => D:/wamp/www/sistemaProtocolo/uploads/ [full_path] => D:/wamp/www/sistemaProtocolo/uploads/311cc35c96ca64b7750cdce8e8f548d1.jpg [raw_name] => 311cc35c96ca64b7750cdce8e8f548d1 [orig_name] => Copia.jpg [client_name] => Copia.jpg [file_ext] => .jpg [file_size] => 851.84 [is_image] => 1 [image_width] => 1144 [image_height] => 857 [image_type] => jpeg [image_size_str] => width="1144" height="857" ) [1] => Array ( [file_name] => aa960f3a2566ab709e9cfc8d10a5db99.jpg [file_type] => image/jpeg [file_path] => D:/wamp/www/sistemaProtocolo/uploads/ [full_path] => D:/wamp/www/sistemaProtocolo/uploads/aa960f3a2566ab709e9cfc8d10a5db99.jpg [raw_name] => aa960f3a2566ab709e9cfc8d10a5db99 [orig_name] => dsds.jpg [client_name] => dsds.jpg [file_ext] => .jpg [file_size] => 877.92 [is_image] => 1 [image_width] => 1029 [image_height] => 772 [image_type] => jpeg [image_size_str] => width="1029" height="772" ) )
The problem is only in the insertion of the BD, it is inserting only one record, someone has idea of what can be?
That answer might help you: How to treat upload muilt the right way
– DNick