0

I can't find a good solution to my problem so I need your help.

I have already created the controller, but I think there's something missing, so I can upload my images in a proper way.
Until now I can upload but then if I try to see them in website, I only can see very strange characters and even the name of images in DB is weird.

My controller:

public function do_upload(){
    $config['upload_path']          = './assets/img/upload';
    $config['allowed_types']        = 'gif|jpg|png';
    $config['max_size']             = 512000;
    $config['max_width']            = 2440;
    $config['max_height']           = 1600;

    $this->load->library('upload', $config);

    if (!$this->upload->do_upload('userfile')) {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    } else {
        $data = array('upload_data' => $this->upload->data());

        $this->load->view('perfil');
    }
}

and my view:

<?php echo form_open(base_url() . 'index.php/perfil/update/' . $perfil[0]->id_user); ?>
<?php echo form_open_multipart('perfil/do_upload');?>
<input type="file" name="imagem" size="9999" class="form-control" id="imagem">
<label class="texto">Email:</label>
<input type="email" name="email" value="<?php echo $perfil[0]->email; ?>" class="form-control outros">
<label class="texto">Nome:</label>
<input type="text" name="nome" value="<?php echo $perfil[0]->nome; ?>" class="form-control outros">
<label class="texto">Morada:</label>
<input type="text" name="morada" value="<?php echo $perfil[0]->contato; ?>" class="form-control outros">
<label class="texto">Contato:</label>
<input type="text" name="contato" value="<?php echo $perfil[0]->morada; ?>" class="form-control outros">
<label class="texto">Password:</label>
<input type="password" name="password" value="<?php echo $perfil[0]->password; ?>" class="form-control outros">
<br>
<div class="col-md-6 offset-md-3">
  <button type="submit" class="btn btn-default btnadmin">Guardar</button><br><br>

my model:

function post($data){
    $this->db->insert('utilizadores', $data);
}
Rahul Raut
  • 623
  • 6
  • 21
Tiago
  • 1
  • 1
  • Where are you calling your `post()` method? There's no code for saving anything in any database at all in your controller. Also, it's a bit unclear if you want to store the image as a blob but get the path or if you want to store the path but get a blob. – M. Eriksson Jun 30 '20 at 17:53
  • I also hope this `$perfil[0]->password` doesn't contain the users password since passwords should never be stored in plain text. – M. Eriksson Jun 30 '20 at 18:00
  • You are nesting forms, that's not possible: https://stackoverflow.com/questions/379610/can-you-nest-html-forms – Vickel Jun 30 '20 at 19:06

0 Answers0