Erro: Message: Undefined index
Boa noite, amigos programadores.
Estou fazendo um sistema em codeigniter, onde faço o upload de imagens para uma pasta e salvo o nome no banco de dados.
Mas a função está me retornando o seguinte erro: Message: Undefined index: img
public function saveServiceOrProduct(){
$user_log = $this->session->userdata('user_id');
if($this->session->userdata('user_id')){
$this->form_validation->set_rules('name', 'Nome', 'trim|required|max_length[100]|xss_clean');
$this->form_validation->set_rules('price', 'Preço', 'trim|required|numerice|max_length[12]|xss_clean');
if ($this->form_validation->run() == TRUE) {
if ($_FILES['img']['name'] != "") {
$config['upload_path'] = './asset/uploads/produtos/';
$config['allowed_types'] = 'jpg|png|jpg|gif';
$config['max_size'] = '5000';
$this->load->library('upload', $config);
if ($this->upload->do_upload("img")) {
$upload_info = $this->upload->data();
$data=array();
$data['codigo']=$this->input->post('codigo');
$data['name']=$this->input->post('name');
$data['price']=$this->input->post('price');
$data['tipo_unidade']=$this->input->post('tipo_unidade');
$data['description']=$this->input->post('description');
$data['imagem']=$upload_info['file_name'];
$this->db->insert('service_and_product',$data);
$this->session->set_userdata('exception','Attachment has been added successfully');
redirect('admin/attachment');
}else{
$this->session->set_userdata('exception_err','Please upload only pdf file');
redirect('admin/attachment');
}
}else{
$this->session->set_userdata('exception_err','Pdf File field should not be empty.');
redirect('admin/attachment');
}
}//no error
else{
$data = array();
$data['attachments']=$this->db->get('attachment')->result();
$data['compnay_info'] = $this->db->query("select * from company where id='1'")->row();
$data['main_content'] = $this->load->view('attachment', $data, true);
$this->load->view('home', $data);
}
}
}
Essa é a função. Quando a executo, ela diz que não consegue achar "img", mas na view ela está declarada. Vejam:
<div class="column-full">
<textarea id="description" name="description" placeholder="Descrição" value="<?php echo set_value('description'); ?>"></textarea>
<input type="file" class="form-control file-field" name="img" />
</div> <!-- / column-full -->
(é uma parte do form).
Alguém pode me ajudar?
Desde já agradeço!
Discussão (1)
Carregando comentários...