1
I’m making a form that has 2 types of uploads: one for image and one for file. It turns out that the extensions of both are different, but when setting the file upload rules the same does not overwrite the previous (image) rules and ends up not accepting the upload. These are the two functions:
// Function to upload the image:
$configImagem['upload_path'] = './files/noticias/imagens';
$configImagem['allowed_types'] = 'gif|jpg|jpeg|png';
$configImagem['file_name'] = 'Img_noticia_'.date('y-m-d_h-i-s');
$this->load->library('upload',$configImagem);
$check = $this->upload->do_upload('imagem');
if($check == TRUE){
return TRUE;
} else if($check == FALSE){
$this->session->set_flashdata('erro', '<strong>Erro:</strong>'.$this->upload->display_errors());
return FALSE;
}
}
// Function to upload the file:
$configArq['upload_path'] = './files/noticias/arquivos';
$configImagem['allowed_types'] = 'pdf|txt|doc';
$configArq['file_name'] = 'Arq_noticia_'.date('y-m-d_h-i-s');
$this->load->library('upload',$configArq);
$this->upload->initialize($configArq);
$checkArq = $this->upload->do_upload('arquivo');
if($checkArq == TRUE){ // caso não ocorra nenhum tipo de erro, o UPLOAD da imagem é feito.
return TRUE;
} else if($checkArq == FALSE){
$this->session->set_flashdata('erro', '<strong>Erro:</strong>'.$this->upload->display_errors());
return FALSE;
}
}
}