Image upload in codeigniter

0

I'm trying to make upload of two images into an existing script of codeigniter version 1.6.1 and the person does not want to update the version. I'm including some options for a person who requested, but I'm getting a bit confused and not knowing how to resolve the upload portion of images. In fact, I do not even need the location of the image or its name to be sent to the database, I just need the two images as soon as I do upload , have the name automatically changed to a predefined name and replace the existing file of the same name. I tried a lot, I searched for a lot of content, but nothing worked.

Basically, one of the images is the logo of the site that when doing upload , will replace the existing logo and the other is a background image of a certificate, which should do the same thing.

View

<script type="text/javascript">
function valida_dados_empresa(form)
    {
        var alerta='';
        if (alerta=='')
        {
            return true;
        }
        else
        {
            alert('Campos requeridos: '+alerta);
            return false;
        }
    }
</script>
<?php
    echo '<body onLoad=setFocus("DEObs");>';
    echo '<div class="tabela_cadastro">';
    echo form_open_multipart('dados_empresa/dados_empresa_cadastra',$form);
    if (!isset($list)){

        ?>
            <div align="center" class="tarja">CADASTRAR DADOS GERAIS </div>
        <?php
    }
    else
    {
            ?>
            <input type="hidden" name="dados_empresa_id" value="<?php echo $list[0]->dados_empresa_id;?>" />
            <div align="center" class="tarja">ATUALIZAR DADOS GERAIS </div>
        <?php
    }
    ?>

    <table align="center">
    <td align="right" style="text-align:right;">Logo do site: </td>
    <td align="left" style="text-align:left;"><input type="file" name="DELogo" id="DELogo" value="<?php if (isset($list[0])){ echo $list[0]->DELogo;}?>" class="input_large" />
    </td>
  </tr>
      <td align="right" style="text-align:right;">Imagem do Certificado: </td>
    <td align="left" style="text-align:left;"><input type="file" name="DECertificado" id="DECertificado" value="<?php if (isset($list[0])){ echo $list[0]->DECertificado;}?>" class="input_large" />
    </td>
  </tr>
    <td align="right" style="text-align:right;">Nome do site: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DENome" id="DENome" value="<?php if (isset($list[0])){ echo $list[0]->DENome;}?>" class="input_large" />
    </td>
  </tr>
   <tr>
    <td align="right" style="text-align:right;">CEP:</td>
    <td align="left" style="text-align:left;"><input type="text" name="DECep" id="DECep" value="<?php if (isset($list[0])){ echo $list[0]->DECep;}?>" onKeyPress="return NumeroInt(event,this);" class="input_little" maxlength="8" /> 
    </td>
  </tr>
    <tr>
    <td align="right" style="text-align:right;">Endere&ccedil;o: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DEEndereco" id="DEEndereco" value="<?php if (isset($list[0])){ echo $list[0]->DEEndereco;}?>" class="input_large" />
    </td>
  </tr>
    <tr>
    <td align="right" style="text-align:right;">Telefones: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DETelefones" id="DETelefones" value="<?php if (isset($list[0])){ echo $list[0]->DETelefones;}?>" class="input_large" />
    </td>
  </tr>
   <tr>
    <td align="right" style="text-align:right;">Cnpj: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DECnpj" id="DECnpj" value="<?php if (isset($list[0])){ echo $list[0]->DECnpj;}?>" class="input_large" />
    </td>
  </tr>
  <tr>
    <td align="right" style="text-align:right;">Inscri&ccedil;&atilde;o Estadual: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DEInscEst" id="DEInscEst" value="<?php if (isset($list[0])){ echo $list[0]->DEInscEst;}?>" class="input_large" />
    </td>
  </tr>
    <tr>
    <td align="right" style="text-align:right;">Site: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DESite" id="DESite" value="<?php if (isset($list[0])){ echo $list[0]->DESite;}?>" class="input_large" />
    </td>
  </tr>
    <tr>
    <td align="right" style="text-align:right;">Usuário do MOIP: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DEMoip" id="DESite" value="<?php if (isset($list[0])){ echo $list[0]->DEMoip;}?>" class="input_large" />
    </td>
  </tr>
  <tr>
    <td align="right" style="text-align:right;">Email: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DEEmail" id="DEEmail" value="<?php if (isset($list[0])){ echo $list[0]->DEEmail;}?>" class="input_large" />
    </td>
  </tr>
     <tr>
    <td align="right" style="text-align:right;">Valor da inscrição:</td>
    <td align="left" style="text-align:left;"><input type="text" name="DEValor" id="DEValor" value="<?php if (isset($list[0])){ echo $list[0]->DEValor;}?>" onKeyPress="return NumeroInt(event,this);" class="input_little" /> 
    </td>
  </tr>
      <td align="right" style="text-align:right;">Valor do certificado digital:</td>
    <td align="left" style="text-align:left;"><input type="text" name="DEValorcertificado" id="DEValorcertificado" value="<?php if (isset($list[0])){ echo $list[0]->DEValorcertificado;}?>" onKeyPress="return NumeroInt(event,this);" class="input_little" /> 
    </td>
  </tr>
      <td align="right" style="text-align:right;">Valor do certificado impresso:</td>
    <td align="left" style="text-align:left;"><input type="text" name="DEValorcertificadoimpresso" id="DEValorcertificadoimpresso" value="<?php if (isset($list[0])){ echo $list[0]->DEValorcertificadoimpresso;}?>" onKeyPress="return NumeroInt(event,this);" class="input_little" /> 
    </td>
  </tr>
     <tr>
        <td align="right" style="text-align:right;">Obs: </td>
        <td align="left" style="text-align:left;"><textarea name="DEObs" id="DEObs" style="width:300px;height:100px;"><?php if (isset($list[0])){ echo $list[0]->DEObs;}?></textarea>
        </td>
    </tr>
    <tr>
        <td align="right" style="text-align:right;">Código do Analytics: </td>
        <td align="left" style="text-align:left;"><textarea name="DEAnalytics" id="DEObs" style="width:300px;height:100px;"><?php if (isset($list[0])){ echo $list[0]->DEAnalytics;}?></textarea>
        </td>
    </tr>
    <tr>
        <td align="right" style="text-align:right;">Copyright do Rodapé: </td>
        <td align="left" style="text-align:left;"><textarea name="DECopyright" id="DEObs" style="width:300px;height:100px;"><?php if (isset($list[0])){ echo $list[0]->DECopyright;}?></textarea>
        </td>
    </tr>



    <tr>
    <td align="right" style="text-align:right;">Quantidade de cursos em destaque na página inicial: </td>
    <td align="left" style="text-align:left;"><input type="text" name="DECursosDestaque" id="DECursosDestaque" value="<?php if (isset($list[0])){ echo $list[0]->DECursosDestaque;}?>" onKeyPress="return NumeroInt(event,this);" class="input_little" maxlength="12" /> 
    </td>
  </tr>
  </table>
<table align="center">
  <tr>
    <td style="vertical-align:top;">
      <input type="submit" value="CONFIRMAR" class="botao" onClick='return valida_dados_empresa(form);'  />
      </form>
    </td>
    <td style="vertical-align:top;"><?php
                    echo form_open('dados_empresa/index');
                ?>
      <input type="submit" value="CANCELAR" class="botao" />
      </form>
    </td>
  </tr>
</table>

Controller

function dados_empresa_cadastrar(){
        if ($this->super_model->security_2(14))
        {
            if ($this->super_model->quant_registros_total('dados_empresa')==0)
            {
                $this->load->view('dados_empresa_cadastrar');
            }
            else
            {
                redirect('dados_empresa/index');
            }
        }
        else
        {
            redirect('dados_empresa/index');
        }
    }
    function dados_empresa_atualizar(){
        if ($this->super_model->security_2(14))
        {
            $data['list'] = $this->dados_empresa_model->dados_empresa_todos();  
            $this->load->view('dados_empresa_cadastrar',$data);
        }
        else
        {
            redirect('dados_empresa/index');
        }
    }
    function dados_empresa_cadastra(){
        if ($this->super_model->security_3(14))
        {   
                    if (!isset($_POST['dados_empresa_id']))
                    {
                            $data = str_replace('"',"'",$_POST);
                            $data ['DEObs'] = ucwords(mb_convert_case($data['DEObs'],MB_CASE_LOWER, "UTF-8"));
                            $dados_empresa_id = $this->dados_empresa_model->dados_empresa_cadastra($data);
                            $this->super_model->historico_atualiza('','Cadastrou dados do empresa cod '.$dados_empresa_id);
                            redirect('dados_empresa/index');
                    }
                    else
                    {
                            $data = str_replace('"',"'",$_POST);
                            $data ['DEObs'] = ucwords(mb_convert_case($data['DEObs'],MB_CASE_LOWER, "UTF-8"));
$this->dados_empresa_model->dados_empresa_atualiza($data);
                            $this->super_model->historico_atualiza('','Atualizou dados do empresa cod '.$data['dados_empresa_id']);
                            redirect('dados_empresa/index');
                    }
        }
        redirect('dados_empresa/index');    
    }

Model

function dados_empresa_cadastra($data) {
    $this->db->insert('dados_empresa', $data); 
    $this->db->select('dados_empresa_id');
    $this->db->from('dados_empresa');
    $this->db->orderby("dados_empresa_id", "desc"); 
    $this->db->limit("1");
    $dados_empresa_id = $this->db->get(); 
    return $dados_empresa_id->row('dados_empresa_id');
}

function dados_empresa_atualiza($data) {
        $this->db->where('dados_empresa_id',$data['dados_empresa_id']);
        $this->db->update('dados_empresa', $data); 
}
    
asked by anonymous 01.10.2018 / 20:36

0 answers