首页 > 解决方案 > codeigniter 保存图像的路径而不是 blob

问题描述

我找不到解决问题的好方法,所以我需要你的帮助。

我已经创建了控制器,但我认为缺少一些东西,所以我可以以适当的方式上传我的图像。
直到现在我可以上传,但是如果我尝试在网站上看到它们,我只能看到非常奇怪的字符,甚至数据库中的图像名称也很奇怪。

我的控制器:

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');
    }
}

和我的观点:

<?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>

我的模型:

function post($data){
    $this->db->insert('utilizadores', $data);
}

标签: phphtmlcodeigniter

解决方案


推荐阅读