Good evening. I would like help if possible.
controller / documents.php
public function clienteAdicionar(){
if(!$this->permission->checkPermission($this->session->userdata('permissao'),'aDocumento')){
$this->session->set_flashdata('error','Você não tem permissão para adicionar documentos.');
redirect(base_url());
}
$this->data['listaCliente'] = $this->documentos_model->getBase('cliente', 'razaosocial', 'ASC');
$this->load->library('form_validation');
$this->data['custom_error'] = '';
if ($this->form_validation->run('documentos') == false) {
$this->data['custom_error'] = (validation_errors() ? '<div class="form_error">' . validation_errors() . '</div>' : false);
} else {
$field_name = "campo_arquivo";
$this->documentos_model->do_upload($field_name);
}
$this->data['view'] = 'documentos/cadastros/adicionarCliente';
$this->load->view('tema/topo', $this->data);
}
And I also have the following function inside the model:
document_model.php
function do_upload()
{
$date = date('d-m-Y');
$config['upload_path'] = './assets/arquivos/'.$date;
$config['allowed_types'] = 'txt|jpg|jpeg|gif|png|pdf|PDF|JPG|JPEG|GIF|PNG';
$config['max_size'] = 0;
$config['max_width'] = '3000';
$config['max_height'] = '2000';
$config['encrypt_name'] = true;
if (!is_dir('./assets/arquivos/'.$date)) {
mkdir('./assets/arquivos/' . $date, 0777, TRUE);
}
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error','Erro ao fazer upload do arquivo, verifique se a extensão do arquivo é permitida.');
redirect(base_url() . 'index.php/documentos/clienteAdicionar/');
}
else
{
//$data = array('upload_data' => $this->upload->data());
return $this->upload->data();
}
}
Add customer: addClient.php
<form class="form-inline" method="post" enctype="multipart/form-data" action="<?php echo current_url(); ?>" id="formArquivo">
<?php
if($this->uri->segment(4)=="editar"){
echo form_hidden('idDocumento',$result->idDocumento);
}
?>
<fieldset>
<legend><i class="icon-plus icon-title"></i> Novo Documento</legend>
<div class="line">
<p>
<label class="control-label">Cliente</label>
<select class="input-xxlarge" name="tipo" id="tipo" style="width: 715px !important;" autofocus>
<option value="">Selecione o Cliente</option>
<? foreach($this->data['listaCliente'] as $listaCliente){ ?>
<option value="<? echo $listaCliente->idCliente; ?>" <? if(isset($result->idAdministrador)){ if($listaCliente->idCliente==$result->idAdministrador){ echo "selected"; } } ?>><? echo $listaCliente->razaosocial; ?></option>
<? } ?>
</select>
<br>
</p>
<p> </p>
</div>
<div class="line">
<label class="control-label">Nome do Arquivo</label>
<input id="dp1" class="input-small" style="width: 701px !important;" name="nomearquivo" value="" type="text" placeholder="Nome do Arquivo" >
</div>
<div class="line">
<label class="control-label">Arquivo </label>
<input id="campo_arquivo" type="file" class="input-small" name="campo_arquivo" /> (txt|pdf|gif|png|jpg|jpeg)
</div>
<div class="button-form line">
<div class="span6 offset3" style="text-align: center">
<? if($this->uri->segment(2)=="editar"){ ?>
<button type="submit" class="btn btn-primary"><i class="icon-ok icon-white"></i> Alterar</button>
<? } else { ?>
<button class="btn btn-success" id="btnContinuar"><i class="icon-plus icon-white"></i> Adicionar</button>
<? } ?>
<a href="<?php echo base_url() ?>index.php/documentos" class="btn"><i class="icon-arrow-left"></i> Voltar</a>
</div>
</div>
</fieldset>
</form>
The error that occurs is that it does not do UPLOAD, the form data does not come, however I change the field to default (userfile), but it also does not work. Can anyone help me?